-
Notifications
You must be signed in to change notification settings - Fork 77
/
solution.cpp
39 lines (37 loc) · 862 Bytes
/
solution.cpp
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
34
35
36
37
38
39
class Solution
{
public:
vector<vector<int> > result;
vector<int> Str;
vector<bool> flag;
void solve(vector<int> temp, int f, int k)
{
if(k == 0)
{
result.push_back(temp);
}
else
{
for(int i=f;i<flag.size();i++)
{
if(flag[i] == false)
{
flag[i] = true;
temp.push_back(Str[i]);
solve(temp,i,k-1);
temp.erase(temp.end()-1);
flag[i] = false;
}
}
}
}
vector<vector<int> > subsets(vector<int> &S)
{
flag.resize(S.size());
sort(S.begin(),S.end());
Str = S;
for(int i=0;i<S.size()+1;i++)
solve(vector<int>(),0,i);
return result;
}
};