-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.java
More file actions
29 lines (27 loc) · 724 Bytes
/
Copy pathsolution.java
File metadata and controls
29 lines (27 loc) · 724 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
// 90. Subsets II
// https://leetcode.com/problems/subsets-ii/
// Medium | Java | Accepted 2025-12-14
// Runtime 2 ms | Memory 45.2 MB
class Solution {
List<List<Integer>> ans = new ArrayList<>();
int[] num;
public List<List<Integer>> subsetsWithDup(int[] nums) {
Arrays.sort(nums);
num = nums;
recurse(0, new ArrayList<>());
return ans;
}
public void recurse(int ind, List<Integer> temp)
{
ans.add(new ArrayList<>(temp));
for(int i = ind; i<num.length; i++)
{
if(i>ind && num[i] == num[i-1])
continue;
temp.add(num[i]);
recurse(i+1, temp);
temp.remove(temp.size()-1);
}
return;
}
}