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
35 lines (33 loc) · 759 Bytes
/
solution.cpp
File metadata and controls
35 lines (33 loc) · 759 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
34
35
class Solution
{
public:
vector<vector<int> > result;
vector<bool> flag;
void solve(vector<int> temp, int k)
{
if(k == 0)
{
result.push_back(temp);
}
else
{
for(int i=temp.empty()?1:temp.back()+1;i<flag.size();i++)
{
if(flag[i] == false)
{
flag[i] = true;
temp.push_back(i);
solve(temp,k-1);
temp.erase(temp.end()-1);
flag[i] = false;
}
}
}
}
vector<vector<int> > combine(int n, int k)
{
flag.resize(n+1,false);
solve(vector<int>(),k);
return result;
}
};