/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* buildTree(int* nums, int l, int r)
{
if(l>r) return NULL;
struct TreeNode* root = (struct TreeNode*)malloc(sizeof(struct TreeNode));
int mid = (r+l)/2;
root->val = nums[mid];
root->left = buildTree(nums, l, mid-1);
root->right = buildTree(nums, mid+1, r);
return root;
}
struct TreeNode* sortedArrayToBST(int* nums, int numsSize){
if(nums==NULL || numsSize<1) return NULL;
int l = 0, r = numsSize-1;
return buildTree(nums, l, r);
}