-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path90. Subsets II.cpp
More file actions
33 lines (32 loc) · 852 Bytes
/
90. Subsets II.cpp
File metadata and controls
33 lines (32 loc) · 852 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
32
33
class Solution {
set<vector<int>> ans;
vector<int> res;
vector<int> nums;
int n;
public:
void f(int index, int lastUsed) {
if(index == -1) {
auto q = vector<int>(res);
sort(q.begin(), q.end());
ans.insert(q);
return;
}
for(int i = lastUsed + 1; i < n; i ++) {
int temp = res[index];
res[index] = nums[i];
f(index - 1, i);
res[index] = temp;
}
}
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
n = nums.size();
this->nums = nums;
ans.insert(vector<int>());
for(int i = 1; i <= n; i ++) {
res.clear();
res.assign(i, 0);
f(i - 1, -1);
}
return vector<vector<int>>(ans.begin(), ans.end());
}
};