```
void sortedArrayToBSTHelper(vector<int> &num, int start, int end, TreeNode *result)
{
if (end < start)
{
return;
}
int mid = (start + end) / 2;
result = new TreeNode(num[mid]);
sortedArrayToBSTHelper(num, start, mid - 1, result->left);
sortedArrayToBSTHelper(num, mid + 1, end, result->right);
}
TreeNode *sortedArrayToBST(vector<int> &num) {
TreeNode *result = NULL;
sortedArrayToBSTHelper(num, 0, num.size() - 1, result);
return result;
}
```