码迷,mamicode.com
首页 > 编程语言 > 详细

给定有序数组,创建高度最小的二叉查找树

时间:2017-05-20 17:16:59      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:space   nts   hit   pos   img   data-   pop   treenode   ret   

技术分享

技术分享


TreeNode createMinimalBST(int arr[], int start, int end)

{
if (end < start)
{
return null;
}
int mid = start + (end - start) / 2;
TreeNode n=new TreeNode(arr[mid]);
n.left=createMinimalBST(arr,start,mid-1);
n.right=createMinimalBST(arr,mid+1,end);
return n;
}
TreeNode createMinimalBST(int array[])
{
return createMinimalBST(array,0,array.length-1);
}

给定有序数组,创建高度最小的二叉查找树

标签:space   nts   hit   pos   img   data-   pop   treenode   ret   

原文地址:http://www.cnblogs.com/lxjshuju/p/6882417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!