My simple accepted Java solution


  • 0
    S

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


  • 0
    S
    This post is deleted!

Log in to reply
 

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