class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
ArrayList<List<Integer>> res=new ArrayList<>();
Arrays.sort(nums);
helper(nums,res,new ArrayList<>(),0);
return res;
}
private void helper(int[] nums,List<List<Integer>> res,List<Integer> list,int index){
res.add(new ArrayList<>(list));
for(int i=index;i<nums.length;i++){
if(i>index&&nums[i]==nums[i-1]){
continue;
}
list.add(nums[i]);
helper(nums,res,list,i+1);
list.remove(list.size()-1);
}
}
}
LeetCode精选100题——第90题——子集 II
最新推荐文章于 2021-04-07 15:14:48 发布