-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay_15.java
More file actions
28 lines (27 loc) · 799 Bytes
/
Copy pathDay_15.java
File metadata and controls
28 lines (27 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Subsets II
class Solution {
public void func(int i,int n,int[] nums,List<Integer> list,List<List<Integer>> ans){
if(i == n){
ans.add(new ArrayList<>(list));
return;
}
list.add(nums[i]);
func(i+1,n,nums,list,ans);
list.remove(list.size()-1);
for(int idx = i+1;idx<n;idx++){
if(nums[i] != nums[idx]){
func(idx,n,nums,list,ans);
return;
}
}
func(n,n,nums,list,ans);
}
public List<List<Integer>> subsetsWithDup(int[] nums) {
int n = nums.length;
Arrays.sort(nums);
List<List<Integer>> ans = new ArrayList<>();
List<Integer> list = new ArrayList<>();
func(0,n,nums,list,ans);
return ans;
}
}