Jingb's Simple Accepted Java Solution


  • 0
    J
    public TreeNode sortedArrayToBST(int[] nums) {
    		if (nums.length == 0)   return null; 
            TreeNode root = new TreeNode(nums[nums.length/2]);
            root.left = sortedArrayToBST(Arrays.copyOfRange(nums, 0, nums.length/2));
            root.right = sortedArrayToBST(Arrays.copyOfRange(nums, nums.length/2 + 1, nums.length));
    		return root;
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.