Reason for WA (Recursive Approach)


#1
TreeNode* createTree(vector<int> &A, vector<int> &B, int s, int e){
    static int i=0;
    if(s>e) return NULL;
    TreeNode* root= new TreeNode(A[i]);
    int index=-1;
    for(int j=s; j<=e; j++){
        if(B[j]=A[i]){
            index=j;
            break;
        }
    }
    i++;
    root->left=createTree(A, B, s, index-1);
    root->right=createTree(A, B, index+1, e);
    return root;
} 
 
TreeNode* Solution::buildTree(vector<int> &A, vector<int> &B){
    int n=A.size();
    int i=0;
    TreeNode* root= createTree(A, B, 0, n-1);
    return root;
}