Java, easy solution

  • 0
    public class Solution {
        public TreeNode sortedArrayToBST(int[] nums) {
            return sortedArrayToBST_M(nums, 0, nums.length);
        public TreeNode sortedArrayToBST_M(int[] nums, int s, int e) {
        		return null;
        	int mid_index = (s+e)/2;
        	TreeNode tn= new TreeNode(nums[mid_index]);
        	tn.right=sortedArrayToBST_M(nums, mid_index+1, e);
        	tn.left = sortedArrayToBST_M(nums, s, mid_index);
    		return tn;

Log in to reply

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