Can anybody tell me why this wouldn't work? #javascript


  • 0
    X

    Can anybody tell me why this wouldn't work?

    var sortedListToBST = function(head) {
      var root = help(head,null);
        return root
       };
      var help = function(head,end){
         if(head==end)return null
         var fast = head;
         var slow = head;
         while(fast!==end && fast.next!==end){
            fast=fast.next.next;
            slow=slow.next;
        }
        var root = new ListNode(slow.val);
        root.left=help(head,slow);
        root.right=help(slow.next,end);
        return root
     }
    

Log in to reply
 

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