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