https://leetcode.com/problems/combinations/
沿用78题的思路
class Solution {
public:
void backTrack(vector<int> ans, vector<int> nums, vector<vector<int>>& res, int times,int k)
{
if(ans.size() == k)
{
res.push_back(ans);
}
else
{
for(int i = times; i<nums.size(); i++)
{
ans.push_back(nums[i]);
backTrack(ans,nums,res,i+,k);
ans.pop_back();
}
}
}
vector<vector<int>> combine(int n, int k) {
vector<vector<int>> res;
vector<int> ans;
vector<int> nums;
for(int i=;i<=n;i++)
nums.push_back(i);
int bgi = ;
backTrack(ans,nums,res,bgi,k);
return res;
}
};
组合
难度中等102收藏分享切换为英文
通过次数
8,578
提交次数
12,943