这个相对链表就easy了。
import java.util.*; /* * public class TreeNode { * int val = 0; * TreeNode left = null; * TreeNode right = null; * } */ public class Solution { /** * * @param num int整型一维数组 * @return TreeNode类 */ public TreeNode sortedArrayToBST (int[] num) { // write code here if(num.length == 0) return null; if(num.length==1) return new TreeNode(num[0]); int left = 0 ; int right = num.length; int mid = right / 2; TreeNode root = new TreeNode(num[mid]); root.left = sortedArrayToBST(Arrays.copyOfRange(num , left , mid)); root.right = sortedArrayToBST(Arrays.copyOfRange(num , mid + 1 , right)); return root; } }