Memory Limited Exceeded


  • 0
    X

    So i want to ask a question ,my submit solution's answer is Memory Limited Exceeded ,Last exxcuted input is [-999,-998,......] [2000,1999,...]
    my code is

    class Solution {
    public:
    TreeNode* build(vector<int> preorder,int pstart,vector<int> inorder,int istart,int length)
    {
    if(length==0) return NULL;
    TreeNode* ans = new TreeNode(preorder[pstart]);
    int k;
    for(k=0; inorder[k+istart]!=ans->val; k++);
    k+=istart;
    ans->left=build(preorder,pstart+1,inorder,istart,k-istart);
    ans->right=build(preorder,k-istart+pstart+1,inorder,k+1,length-k+istart-1);
    return ans;
    }
    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
    return build(preorder,0,inorder,0,inorder.size());
    }
    };


Log in to reply
 

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