鼓掌鼓掌,刷题以来,第一道一次accept的题目,也难怪通过率这么高
class Solution {
public:
vector<vector<int>> res;
vector<vector<int> > combine(int n, int k) {
vector<int>path;
process(n,1,k,path);
return res;
}
void process(int n,int cur,int k,vector<int>&path)
{
if(k==0)
{
res.push_back(path);
return ;
}
int t;
for(int i=cur;i<=n;i++)
{
t=k-1;
path.push_back(i);
if(t>=0)
{
process(n,i+1,t,path);
}
path.pop_back();
t=k;
}
}
};