leetcode-77-组合

class Solution {

public:

    vector<vector<int>> res;

    void helper(int begin, int n, int k, vector<int> curres){

        if (curres.size() == k) res.push_back(curres);

        else{

            for (int i=begin; i<=n-(k-curres.size())+1; i++){

                curres.push_back(i);

                helper(i+1, n, k, curres);

                curres.pop_back();

            }

        }

        return;

    }

    vector<vector<int>> combine(int n, int k) {

        helper(1,n, k, vector<int>());

        return res;

    }

};

相关文章:

  • 2021-06-06
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2021-04-25
  • 2021-08-05
  • 2021-04-04
  • 2021-07-21
猜你喜欢
  • 2021-07-11
  • 2021-09-16
  • 2021-12-09
  • 2022-12-23
  • 2021-12-28
  • 2022-01-27
  • 2022-02-08
相关资源
相似解决方案