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