class Solution
{
public:
    vector<vector<int> > combine(int n, int k) 
    {
        vector<int> vecTmp;
        
        m_vecRet.clear();
        combination(1, n, vecTmp, k);
        
        return m_vecRet;
    }
    
private:
    void combination(int from, int to, vector<int> &curr, int k)
    {
        if (k == 0)
        {
            m_vecRet.push_back(curr);
        }
        else if (from > to)
        {
            return;
        }
        else
        {
            curr.push_back(from);
            combination(from + 1, to, curr, k - 1);
            curr.pop_back();
            combination(from + 1, to, curr, k);
        }
    }
    
private:
    vector<vector<int> > m_vecRet;
};

相关文章:

  • 2021-08-15
  • 2022-03-01
  • 2021-08-02
  • 2022-01-10
  • 2021-05-23
猜你喜欢
  • 2021-11-11
  • 2021-05-21
  • 2021-06-12
相关资源
相似解决方案