Middle-题目15：108. Convert Sorted Array to Binary Search Tree

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

public class Solution {
public TreeNode sortedArrayToBST(int[] nums) {
if(nums.length==0)
return null;
TreeNode bst=createBST(nums,0,nums.length-1);
return bst;
}
public TreeNode createBST(int[] nums,int start,int end) {
int mid = (start + end) / 2;
TreeNode root = new TreeNode(nums[mid]);
if(start < mid )
root.left = createBST(nums,start,mid-1);
if(mid  < end)
root.right = createBST(nums,mid+1,end);
return root;
}
}

1ms,beats 7.24%,众数1ms,92.62%

Middle-题目122：220. Contains Duplicate III

2016-05-31 20:13:20

Middle-题目120：179. Largest Number

2016-05-31 20:11:04

Middle-题目117：98. Validate Binary Search Tree

2016-05-31 20:07:10

Middle-题目114：3. Longest Substring Without Repeating Characters

2016-05-31 20:05:37

2016-05-31 20:00:40

LeetCode OJ 108. Convert Sorted Array to Binary Search Tree DFS求解

2016-02-25 19:35:34

LeetCode(108)Convert Sorted Array to Binary Search Tree

2014-01-18 02:17:01

108. Convert Sorted Array to Binary Search Tree Leetcode Python

2015-01-16 07:36:06

Convert Sorted Array to Binary Search Tree -- LeetCode

2014-04-17 07:56:34

leetcode-java-108. Convert Sorted Array to Binary Search Tree

2016-08-16 14:45:18