I have the same problem as yours,modify (left,mid) to (left,mid-1) would be OK

class Solution {
public:
TreeNode *ArrayToBST(vector<int> &num,int low,int high)
{
if(num.size()==0) return NULL;
TreeNode *root;
if(low>high) return NULL;
if(low==high)
{
root=new TreeNode(num[low]);
return root;
}
int mid=(low+high)/2;
root=new TreeNode(num[mid]);
root->left=ArrayToBST(num,low,mid-1);
root->right=ArrayToBST(num,mid+1,high);
return root;
}
TreeNode *sortedArrayToBST(vector<int> &num) {
return ArrayToBST(num,0,num.size()-1);
}
};