void comb(int n, int index, int k, vector<vector<int> > &res, vector<int> &temp)
{
if(temp.size()==k)
res.push_back(temp);
for(int i=index; i<=n; ++i)
{
temp.push_back(i);
comb(n, i+1, k, res, temp);
temp.pop_back();
}
}
vector<vector<int> > combine(int n, int k)
{
vector<vector<int> > ans;
ans.clear();
vector<int> temp;
temp.clear();
if(n<k || n<1 || k<1)
return ans;
comb(n,1,k,ans,temp);
return ans;
}
LeetCode-Combinations
最新推荐文章于 2020-10-16 16:01:05 发布