/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */publicclassSolution{publicTreeNodesortedArrayToBST(int[]nums){intn=nums.length;if(n==0)returnnull;TreeNoderoot=newTreeNode(nums[n/2]);root.left=sortedArrayToBST(Arrays.copyOfRange(nums,0,n/2));root.right=sortedArrayToBST(Arrays.copyOfRange(nums,n/2+1,n));returnroot;}}