二分得变种吧~
高度最小的BST
http://www.nowcoder.com/questionTerminal/01a12f94988649e39b554d95c45bfa6f
其实就是将数组分割成,每个小数组的大小为小于等于1,直至不能再分。
public int buildMinimalBST(int[] vals) { if(vals.length == 0) return 0; if(vals.length == 1) return 1; int mid = vals.length/2; int[] left = Arrays.copyOfRange(vals,0,mid); int[] right = Arrays.copyOfRange(vals,mid+1,vals.length); return (Math.max(buildMinimalBST(left)+1,buildMinimalBST(right)+1)); }