-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_0090SubSetsii.java
More file actions
31 lines (26 loc) · 866 Bytes
/
_0090SubSetsii.java
File metadata and controls
31 lines (26 loc) · 866 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
29
30
31
package com.heatwave.leetcode.problems;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class _0090SubSetsii {
static class Solution {
List<Integer> temp = new ArrayList<>();
List<List<Integer>> ans = new ArrayList<>();
public List<List<Integer>> subsetsWithDup(int[] nums) {
Arrays.sort(nums);
backtracking(nums, 0);
return ans;
}
private void backtracking(int[] nums, int index) {
ans.add(new ArrayList<>(temp));
for (int i = index; i < nums.length; i++) {
if (i > index && nums[i] == nums[i - 1]) {
continue;
}
temp.add(nums[i]);
backtracking(nums, i + 1);
temp.remove(temp.size() - 1);
}
}
}
}