标签:
/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ struct TreeNode* built_bst(int* nums,int start,int end){ int mid; mid=(start+end)/2; if(start>end)return NULL; struct TreeNode *p; p=(struct TreeNode*)malloc(sizeof(struct TreeNode)); p->val=nums[mid]; p->left=built_bst(nums,start,mid-1); p->right=built_bst(nums,mid+1,end ); return p; } struct TreeNode* sortedArrayToBST(int* nums, int numsSize) { struct TreeNode *root; root=built_bst(nums,0,numsSize-1); return root; }
Convert Sorted Array to Binary Search Tree || LeetCode
标签:
原文地址:http://www.cnblogs.com/ProtectedDream/p/4561338.html