Check this solution


#1

What do you think why this solution isn’t working?

template
TreeNode* f(T b, T e){
if(b==e) return NULL;
T i=b+(e-b)/2;
TreeNode* ans= new TreeNode(i);
ans->left=f(b,i);
ans->right=f(i+1,e);
return ans;
}
TreeNode
Solution::sortedArrayToBST(const vector &A) {
return f(A.begin(),A.end());
}

It works on my computer when I run it.


#2

I think you should also check for the condition when b < e


#3

The solution is correct. They’ve fixed the problem after several days. Their mistake costed me only few hundred points xD