forked from moranzcw/LeetCode-NOTES
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.cpp
More file actions
33 lines (32 loc) · 687 Bytes
/
solution.cpp
File metadata and controls
33 lines (32 loc) · 687 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
{
public:
vector<vector<int> > v;
vector<vector<int> > subsetsWithDup(vector<int> &S)
{
sort(S.begin(),S.end());
generate(vector<int>(), S, 0);
return v;
}
void generate(vector<int> res, vector<int> &S, int i)
{
if(i == S.size())
{
for(int i = 0; i < v.size(); i++)
{
if(v[i] == res)
{
return;
}
}
v.push_back(res);
return;
}
else
{
generate(res, S, i+1);
res.push_back(S[i]);
generate(res, S, i+1);
}
}
};