Python 56ms solution

  • 1
    class Solution(object):
        def mergeTwoLists(self, l1, l2):
            :type l1: ListNode
            :type l2: ListNode
            :rtype: ListNode
            if l1 is None:
                return l2
            if l2 is None:
                return l1
            f = l1
            s = l2
            newHead = new = ListNode('dummy')
            while f and s:
                if f.val <= s.val:
           = f
                    f =
           = s
                    s =
                new =
   = f if f else s

Log in to reply

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