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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.