Why Output Limit Exceeded


  • -1
    G

    I have a problem of Output Limit Exceeded, I checked code several times but can't find where is wrong. May anyone kindly told me where is wrong?

    Thank you.

    class Solution {
    public:
        void dfs(int now, int n, int k, vector<int> &tmp, vector<vector<int> > &r) {
            if (k == 0) {
                r.push_back(tmp);
                return;
            }
            for (int i = now; i <= n - k; ++i) {
                tmp.push_back(i + 1);
                dfs(now + 1, n, k - 1, tmp, r);
                tmp.pop_back();
            }
        }
        vector<vector<int> > combine(int n, int k) {
    
            vector<vector<int> > r;
            vector<int> tmp;
            dfs(0, n, k, tmp, r);
            return r;
        }
     
    };

  • 0
    H

    the code in line 10 should be:
    dfs(i + 1, n, k - 1, tmp, r);
    because now i+1 is selected, then the following numbers should start from i + 2.


Log in to reply
 

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