题目:
代码(首刷看解析 2024年2月1日):
class Solution {
public:vector<vector<int>> res;vector<int> path;void backtracing(int n, int k, int startIndex) {if (path.size() == k) {res.push_back(path);return;}for (int i = startIndex; i < n + 1; ++i) {path.push_back(i);backtracing(n, k, i+1);path.pop_back();}return;}vector<vector<int>> combine(int n, int k) {backtracing(n, k, 1);return res;}
};