Need help to find the error!


#1

This is my code (getting memory limit exceeded):

// to find the index of k in inorder array
int fi(int k,const vector&inn,int s,int e)
{
for(int i=s;i<=e;i++)
{
if(inn[i]==k)return i;
}
return -1;
}

TreeNode* itp(const vector&pre,const vector&inn, int s,int e)
{
static int i=0;
if(s>e)return NULL;
if(s==e)
{
TreeNoder=new TreeNode(pre[i]);return r;
}
int f=fi(pre[i],inn,s,e);
TreeNode
root=new TreeNode(pre[i]);
root->left=itp(pre,inn,s,f-1);
root->right=itp(pre,inn,f+1,e);
i++;
return root;

}

TreeNode* Solution::buildTree(vector &A, vector &B) {
int n=A.size();
return itp(A,B,0,n-1);
}