首页 > 其他 > 详细

108. Convert Sorted Array to Binary Search Tree

时间:2018-09-20 10:22:32      阅读:132      评论:0      收藏:0      [点我收藏+]
 1 class Solution {
 2     public TreeNode sortedArrayToBST(int[] nums) {
 3         int size = nums.length;
 4         return helper(nums, 0, size - 1);
 5         
 6     }
 7     
 8     public TreeNode helper(int[] nums, int lo, int hi) {
 9         if(lo > hi) return null;
10         int mid = lo + (hi - lo) / 2;
11         TreeNode root = new TreeNode(nums[mid]);
12         root.left = helper(nums, lo , mid-1);
13         root.right = helper(nums, mid+1, hi);
14         return root;
15     }
16 }

 

108. Convert Sorted Array to Binary Search Tree

原文:https://www.cnblogs.com/goPanama/p/9678665.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!