-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
27 lines (24 loc) · 850 Bytes
/
Solution.java
File metadata and controls
27 lines (24 loc) · 850 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
class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> res = new ArrayList<List<Integer>>();
Arrays.sort(nums);
backTrack(0, nums, new ArrayList<Integer>(), res);
return res;
}
public void backTrack(int beg, int[] nums, List<Integer> temp, List<List<Integer>> res) {
if (beg <= nums.length) {
res.add(temp);
int i = beg;
while (i < nums.length) {
int num = nums[i];
List<Integer> t = new ArrayList<Integer>(temp);
t.add(num);
backTrack(i + 1, nums, t, res);
while (i + 1 < nums.length && nums[i + 1] == num) {
i++;
}
i++;
}
}
}
}