首页 > 其他 > 详细

[LeetCode]90 Subsets II

时间:2015-01-05 07:11:04      阅读:265      评论:0      收藏:0      [点我收藏+]

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

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

public class Solution {
    public List<List<Integer>> subsetsWithDup(int[] num) {
        
        Arrays.sort(num);
        
        Set<List<Integer>> results = new HashSet<>();
        help(num, 0, new ArrayList<Integer>(), results);
        return new ArrayList<List<Integer>>(results);
    }
    
    // Don‘t know how to handle duplicate cases :(
    // Using set
    private void help(int[] n, int start, List<Integer> items, Set<List<Integer>> results)
    {
        results.add(new ArrayList<Integer>(items));
        
        for (int i = start ; i < n.length ; i ++)
        {
            items.add(n[i]);
            
            help(n, i + 1, items, results);
            
            items.remove(items.size() - 1);
        }
    }
}


[LeetCode]90 Subsets II

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

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