-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubsets II.java
More file actions
21 lines (21 loc) · 781 Bytes
/
Subsets II.java
File metadata and controls
21 lines (21 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> result = new LinkedList<List<Integer>>();
if (nums == null || nums.length == 0) {
return result;
}
Arrays.sort(nums);
process(result, new LinkedList<Integer>(), 0, nums);
return result;
}
private void process(List<List<Integer>> result, List<Integer> curr, int start, int[] nums) {
result.add(new LinkedList<Integer>(curr));
for (int i = start; i < nums.length; i ++) {
if (i == start || nums[i] != nums[i-1]){
curr.add(nums[i]);
process(result, curr, i + 1, nums);
curr.remove(curr.size() - 1);
}
}
}
}