LeetCode 77. Combinations

2019-11-04 02:45:51 浏览数 (1)

代码语言:javascript复制
class Solution {
public:
    vector<vector<int>> ans;
    vector<vector<int>> combine(int n, int k) {
          
        if(k>n)
            return ans;
        vector<int> res;
        fun(0,0,n,k,res);
        return ans;
    }
    
    
    void fun(int n1,int k1,int n,int k,vector<int> res)
    {
        
        if(k1==k)
        {
            ans.push_back(res);
            return;
        }
        
        for(int i=n1 1;i<=n;i  )
        {
            res.push_back(i);
            fun(i,k1 1,n,k,res);
            res.pop_back();
        }
    }
};
ode

0 人点赞