a JavaScript recursion solution


  • 0
    M
    function mergeTwoLists(a,b) {
      if (a === null) return b;
      if (b === null) return a;
    
      if (a.val < b.val) {
        a.next = mergeTwoLists(a.next, b);
        return a;
      } else {
        b.next = mergeTwoLists(b.next, a);
        return b;
      }
    }
    

Log in to reply
 

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