/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
TreeNode *sortedArrayToBST(vector<int> &num) {
return sortedArrayToBST(0, num.size()-1, num);
}
TreeNode *sortedArrayToBST(int left, int right, vector<int> &num){
if (left > right)
return NULL;
int mid = (left + right)/2 + (left + right)%2 ;
TreeNode *root = new TreeNode(num[mid]);
root->left = sortedArrayToBST(left, mid-1, num);
root->right = sortedArrayToBST(mid+1, right, num);
return root;
}
};