JAVA - My 6 lines solution


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

  • 1
    Y

    Wow !( ̄▽ ̄)~*
    It's very clear. Thank you for sharing/


Log in to reply
 

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