递归,分治
有序数组选中间点m作为root,recursiely build subtrees
m.left = build [l, m)
m.right = build [m+1, r)
public class Solution {
public TreeNode sortedArrayToBST (int[] num) {
if (num.length == 0) return null;
return build(num, 0, num.length);
}
// build the BST for num[l:r)
TreeNode build(int[] num, int l, int r) {
if (l == r) return null;
int m = l + ((r - l) >> 2);
TreeNode n = new TreeNode(num[m]);
n.left = build(num, l, m);
n.right = build(num, m+1, r);
return n;
}
}