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