-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathLeetCode#63.cc
More file actions
32 lines (27 loc) · 748 Bytes
/
Copy pathLeetCode#63.cc
File metadata and controls
32 lines (27 loc) · 748 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
class Solution {
private:
void dfs(int ind, int cnt, int n, int k,vector<int>& tmp, vector<vector<int> >& res){
if(cnt==k){
res.push_back(tmp);
return ;
}
for(int i=ind;i<=n;i++){
tmp[cnt]=i;
dfs(i+1,cnt+1,n,k,tmp,res);
}
}
public:
vector<vector<int> > combine(int n, int k) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<vector<int> > ret;
if(k>n) return ret;
if(k==0){
ret.push_back(vector<int>());
return ret;
}
vector<int> tmp(k,0);
dfs(1,0,n,k,tmp,ret);
return ret;
}
};