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

90. Subsets II

时间:2017-09-28 14:06:34      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:.so   arrays   turn   hdu   []   with   for   pre   rem   

public class Solution {
    public List<List<Integer>> subsetsWithDup(int[] nums) {
        List<List<Integer>> res=new ArrayList<List<Integer>>();
        Arrays.sort(nums);
        subsetsWithDup(0, new ArrayList<Integer>(), res, nums);
        return res;
    }
    private void subsetsWithDup(int idx, List<Integer> list, List<List<Integer>> res, int[] nums){
        res.add(new ArrayList<Integer>(list));
        for(int i=idx;i<nums.length;i++)
        {
            if(i!=idx&&nums[i]==nums[i-1])
                continue;
            list.add(nums[i]);
            subsetsWithDup(i+1,list,res,nums);
            list.remove(list.size()-1);
        }
    }
}

 

90. Subsets II

标签:.so   arrays   turn   hdu   []   with   for   pre   rem   

原文地址:http://www.cnblogs.com/asuran/p/7606187.html

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