8ms beats 100.00% of cpp submissions


  • 0
    T
    class Solution {
    public:
        vector<int> per;
        vector< vector<int> > ans;
        vector< vector<int> > combine(int n, int k) {
            ans.clear();
            per.resize(k);
            generateCombine(n,k,1,0);
            return ans;
        }
        void generateCombine(int n, int k, int start , int index) {
            if (k==0)
            {
                ans.push_back(per);
                return ;
            }
            for(int i=start;i<=n;i++)
            {
                per[index] = i;
                generateCombine(n,k-1,i+1,index+1);
            }
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.