-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path152.h
More file actions
30 lines (27 loc) · 754 Bytes
/
152.h
File metadata and controls
30 lines (27 loc) · 754 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
class Solution {
public:
/*
* @param n: Given the range of numbers
* @param k: Given the numbers of combinations
* @return: All the combinations of k numbers out of 1..n
*/
vector<vector<int>> combine(int n, int k) {
// write your code here
vector<vector<int>> res;
vector<int> r;
combine(n, k, 1, r, res);
return res;
}
void combine(int n, int k, int start,
vector<int> &r, vector<vector<int>> &res){
if(k == 0){
res.push_back(r);
return;
}
for(int i = start; i <= n; i++){
r.push_back(i);
combine(n, k-1, i+1, r, res);
r.pop_back();
}
}
};