Binary Search Approach Recursive CPP Solution


#1

TreeNode* get_me_ans(vector& vec,int l,int r)
{
if(l>r)
return NULL;

int mid= l + (r-l)/2;

TreeNode * ans =  new TreeNode(vec[mid]);

ans->left=get_me_ans(vec,l,mid-1);
ans->right=get_me_ans(vec,mid+1,r);

return ans;

}
TreeNode* Solution::sortedArrayToBST(const vector &A) {
vectorvec=A;

TreeNode* ans = get_me_ans(vec,0,vec.size()-1);

return ans;

}