Combinations

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;
};
原文地址:https://www.cnblogs.com/codingmylife/p/2667056.html