77. 组合
class Solution { public: vector<vector<int>> res; vector<int> path; void backTracking(int n,int k,int startIndex) { if(path.size()==k) { res.push_back(path);return; } //for(int i=startIndex;i<=n;i++) for(int i=startIndex;i<=n-(k-path.size())+1;i++) { path.push_back(i); backTracking(n,k,i+1); path.pop_back(); } } vector<vector<int>> combine(int n, int k) { backTracking(n,k,1); return res; } };
标签:return,leetcode77,组合,int,res,startIndex,path From: https://www.cnblogs.com/uacs2024/p/16723491.html