Skip to content

Commit 99f1935

Browse files
90. Subsets II (java)
1 parent dedbc8b commit 99f1935

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public List<List<Integer>> subsetsWithDup(int[] nums) {
3+
List<List<Integer>> res = new ArrayList<>();
4+
if(nums==null||nums.length==0) return res;
5+
Arrays.sort(nums);
6+
backTrack(res, nums, 0, new ArrayList<>());
7+
return res;
8+
}
9+
private void backTrack(List<List<Integer>> res, int[] nums, int index, List<Integer> ls){
10+
res.add(new ArrayList<>(ls));
11+
if(index>=nums.length) return;
12+
for(int i=index;i<nums.length;i++){
13+
ls.add(nums[i]);
14+
backTrack(res, nums, i+1, ls);
15+
ls.remove(ls.size()-1);
16+
while(i<nums.length-1 && nums[i+1]==nums[i]) i++;
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)