题解 | #字符串的全部子序列#

字符串的全部子序列

http://www.nowcoder.com/practice/92e6247998294f2c933906fdedbc6e6a

import java.util.*;


public class Solution {
    
    HashSet<String> res = new HashSet<>();
    
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param s string字符串 
     * @return string字符串一维数组
     */
    public String[] generatePermutation (String s) {
        // write code here
        process(s, 0, "");
        return res.toArray(new String[0]);
    }
    
    public void process(String str, int start, String tmp) {
        String copyStr = new String(tmp);
        res.add(copyStr);
        if (start >= str.length()) {
            return;
        }
        for (int i = start; i < str.length(); i++) {
            String tmpStr = new String(tmp);
            tmpStr += str.charAt(i);
            process(str, i + 1, tmpStr);
        }
    }
}
全部评论

相关推荐

面了100年面试不知...:太礼貌,还是
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务