Share my JAVA code

  • 1

    Below is my java solution. Hope it helps :)

     public class Solution {
            public TreeNode sortedArrayToBST(int[] num) {
                return build(num,0,num.length-1);
            private TreeNode build(int[] num, int right,int left)
                if(right>left) return null;
                int middle = (right+left)/2;
                TreeNode node = new TreeNode(num[middle]);
                node.left = build(num,right,middle-1);
                node.right = build(num,middle+1,left);
                return node;

Log in to reply

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