标签:div sea sort balance bin node where create 含义
Given an array where elements are sorted in ascending order, convert it to a height balanced BST.
题目含义:给定了一个升序的数组,转换成一个平衡二叉树
1 private TreeNode createMidTree(int[] nums,int begin,int end) 2 { 3 if (begin>end) return null; 4 int middle = (begin+end)/2; 5 TreeNode node = new TreeNode(nums[middle]); 6 node.left = createMidTree(nums,begin,middle-1); 7 node.right = createMidTree(nums,middle+1,end); 8 return node; 9 } 10 11 public TreeNode sortedArrayToBST(int[] nums) { 12 if(nums.length==0) return null; 13 return createMidTree(nums,0,nums.length-1); 14 }
108. Convert Sorted Array to Binary Search Tree
标签:div sea sort balance bin node where create 含义
原文地址:http://www.cnblogs.com/wzj4858/p/7705383.html