输出给定String所有可能的subsequence

http://www.1point3acres.com/bbs/thread-297207-1-1.html

    public static List<String> subsequenceOfString(String s) {
            if (s == null || s.length() == 0) {
                    return new LinkedList<>();
            }

            Set<String> set = new HashSet<>();
            helper(s, set, new StringBuilder(), 0);
            List<String> res = new LinkedList<>(set);. visit 1point3acres.com for more.

            return res;
    }

    public static void helper(String s, Set<String> res, StringBuilder sb, int pos) {
            if (sb.length() != 0) {
                    res.add(sb.toString());
            }

            for (int i = pos; i < s.length(); i++) {
                    sb.append(s.charAt(i));
                    helper(s, res, sb, i + 1);
                    sb.deleteCharAt(sb.length() - 1);
            }
    }

results matching ""

    No results matching ""