/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: TreeNode* sortedArrayToBST(vector & nums) { int len=nums.size(); return soln(nums,0,len); } TreeNode* soln(vector & nums,int bg,int ed) { int mid=bg+(ed-bg)/2; if(mid==ed){ return NULL; } TreeNode *res=new TreeNode(nums[mid]); res->left=soln(nums,bg,mid); res->right=soln(nums,mid+1,ed); return res; }};