Why i am getting wrong answer?


#1

TreeNode* build(vector &A,vector &B,int s,int e,int &preorder){
if(s>e)
return NULL;
int c=B[preorder++];
TreeNode *root=new TreeNode©;
int i;
for(i=s;i<=e;i++){
if(A[i]==c){

        break;
    }
}
root->left=build(A,B,s,i-1,preorder);
root->right=build(A,B,i+1,e,preorder);

return root;

}
TreeNode* Solution::buildTree(vector &A, vector &B) {
int n=B.size()-1;
int preorder=0;
/unordered_map<int,int> map;
for(int i=0;i<A.size();i++){
map[A[i]]=i;
}
/
return build(A,B,0,n,preorder);

}