Whats wrong in it?


#1

TreeNode* Solution::sortedArrayToBST(const vector &A) {
int n = A.size();
int mid = n/2;

TreeNode* root = new TreeNode(A[mid]);
TreeNode* B = root;
int i= mid-1;
while(i>=0)
{
    B->left = new TreeNode(A[i]);
    i--;
    B = B->left;
    B->right = NULL;
}
B->left = NULL;
B = root;
i=mid+1;
while(i<n)
{
    B->right = new TreeNode(A[i]);
    i++;
    B=B->right;
    B->left=NULL;
}
B->right = NULL;

return root;

}