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();
         }
    }
};
posted @ 2020-07-14 18:34  景云ⁿ  阅读(65)  评论(0编辑  收藏  举报