Why Memory Limit Exceeded


  • 0
    W

    here is my code:

    class Solution {
    private:
        vector<vector<int>> result;
        vector<int> path;
    public:
        void dfs(int curDeep, int maxDeep, int start , int n)
        {
            if(curDeep == maxDeep)
            {
                result.push_back(path);
                return ;
            }
            for(int i = start; i <= n; i++)
            {
                path[curDeep] = i;
                dfs(curDeep + 1, maxDeep, start + 1, n);
            }
        }
        vector<vector<int> > combine(int n, int k) {
            path.resize(k);
            this->dfs(0, k, 1, n);
            return result;
        }
    };
    

    i do not know the reason why I get this error:Memory Limit Exceeded pls help~ thank you


  • 0
    G

    the content in the for-cycle in dfs should be :
    path[curDeep] = i;
    if(curDeep + 1 > maxDeep) return ;
    dfs(curDeep + 1, maxDeep, i + 1, n, result, path);


  • 0
    J

    Did you figure out your problem? I'm getting the same error, and I noticed our code logics are similar. Thanks.


Log in to reply
 

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