108. Convert Sorted Array to Binary Search Tree
和104,105一个方法
1 public TreeNode sortedArrayToBST(int[] nums) { 2 if(nums.length == 0) { 3 return null; 4 } 5 return helper(nums, 0, nums.length - 1); 6 } 7 8 private TreeNode helper(int[] nums, int start, int end) { 9 if(start > end) { 10 return null; 11 } 12 int rootIndex = start + (end - start) / 2; 13 TreeNode root = new TreeNode(nums[rootIndex]); 14 root.left = helper(nums, start, rootIndex - 1); 15 root.right = helper(nums, rootIndex + 1, end); 16 return root; 17 }