码迷,mamicode.com
首页 > 其他好文 > 详细

subsequence of String

时间:2017-12-25 11:32:04      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:new   body   hello   oid   UI   seq   add   string   fst   

 

public class Solution{
    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);

        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);
        }
    }
    public static void main(String[] args){

        String s = "hello";
        Solution sol = new Solution();

        System.out.println(sol.subsequenceOfString(s));

    }
}

  

subsequence of String

标签:new   body   hello   oid   UI   seq   add   string   fst   

原文地址:http://www.cnblogs.com/apanda009/p/8107856.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!