public TreeNode sortedArrayToBST(int[] nums) {

if (nums.length == 0)

return null;

int index = nums.length / 2;

int[] left = Arrays.copyOfRange(nums, 0, index);

int[] right = Arrays.copyOfRange(nums, index + 1, nums.length);

int val = nums[index];

TreeNode root = new TreeNode(val);

root.left = sortedArrayToBST(left);

root.right = sortedArrayToBST(right);

return root;

}