这道题的难点就在于是否能够发现其实每次都需要将下中位点拿来做根节点,hhh
public TreeNode sortedArrayToBST (int[] num) { if(num==null||num.length==0) return null; return createBST(num,0,num.length-1); } public TreeNode createBST(int[] num,int start,int end){ if(start>end){ return null; } int mid = (end+start+1)>>1;//这个+1是精髓 TreeNode head = new TreeNode(num[mid]); TreeNode left = createBST(num,start,mid-1); TreeNode right = createBST(num,mid+1,end); head.left = left; head.right = right; return head; }