5 lines in Ruby


  • 0
    A
    def merge_two_lists(l1,l2)
      return l1 if not l2
      return l2 if not l1
      l1,l2 = l2, l1 if l1.val > l2.val  ## swap
      l1.next=merge_two_lists(l1.next,l2)
      l1
    end

Log in to reply
 

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