首页 > 其他 > 详细

[LeetCode]78 Subsets

时间:2015-01-04 19:32:53      阅读:246      评论:0      收藏:0      [点我收藏+]

https://oj.leetcode.com/problems/subsets/

http://blog.csdn.net/linhuanmars/article/details/24286377

public class Solution {
    public List<List<Integer>> subsets(int[] S) {
        
        Arrays.sort(S);

        List<List<Integer>> results = new ArrayList<>();
        help(S, 0, new ArrayList<Integer>(), results);
        return results;
    }
    
    private void help(int[] S, int start, List<Integer> items, List<List<Integer>> results)
    {
        if (items.size() <= S.length)
        {
            results.add(new ArrayList<Integer>(items));    
        }
        
        if (items.size() == S.length)
            return;
        
        for (int i = start ; i < S.length ; i ++)
        {
            items.add(S[i]);
            
            help(S, i + 1, items, results);
            
            items.remove(items.size() - 1);
        }
    }
}


[LeetCode]78 Subsets

原文:http://7371901.blog.51cto.com/7361901/1599002

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!