原题链接:https://leetcode.com/problems/combinations/
class Solution {
public:
vector<vector<int>> res;
vector<vector<int>> combine(int n, int k) {
vector<int> path;
dfs(path, 1, n, k);
return res;
}
void dfs(vector<int> &path, int start, int n, int k) {
if (!k) {
res.push_back(path);
return;
}
for (int i = start; i <= n; i ++ ) {
path.push_back(i);
dfs(path, i + 1, n, k - 1);
path.pop_back();
}
}
};