【leetcode】Combinations

来源:互联网 发布:淘宝满就减怎么设置 编辑:程序博客网 时间:2024/05/01 19:16
class Solution {public:        vector<vector<int> >ans;    vector<int>tmp;    void dfs(int dep,int maxDep,int start,int end)    {        if(dep==maxDep)        {            ans.push_back(tmp);            return;        }        for(int i=start;i<=end;i++)        {            tmp[dep]=i;            dfs(dep+1,maxDep,i+1,end);//        }    }    vector<vector<int> > combine(int n, int k) {        // Start typing your C/C++ solution below        // DO NOT write int main() function        tmp.resize(k);        ans.clear();        dfs(0,k,1,n);        return ans;    }};

原创粉丝点击