Easy CPP solution recursively done....have a look


#1

TreeNode* form(const vector &A,int start,int end)
{
int mid=(start+end)/2;
if(end-start<=2)
{
TreeNode* aux=new TreeNode(A[mid]);
if(mid>start)
aux->left=new TreeNode(A[start]);
if(mid<end)
aux->right=new TreeNode(A[end]);
return aux;
}
TreeNode* root=new TreeNode(A[mid]);
root->left=form(A,start,mid-1);
root->right=form(A,mid+1,end);
return root;
}
TreeNode* Solution::sortedArrayToBST(const vector &A) {
int n=A.size();
if(n==0)
return NULL;
TreeNode* root=form(A,0,n-1); // root formation
return root;
}