leetcode-----77. 组合

代码

class Solution {
public:
    vector<vector<int>> ans; 
    vector<int> path;

    vector<vector<int>> combine(int n, int k) {
        dfs(n, k, 1);
        return ans;
    }

    void dfs(int n, int k, int start) {
         if (!k) {
             ans.push_back(path);
             return;
         }
         for (int i = start; i <= n; ++i) {
             path.push_back(i);
             dfs(n, k - 1, i + 1);
             path.pop_back();
         }
    }
};
原文地址:https://www.cnblogs.com/clown9804/p/13300820.html