Python non-recursive solution

  • -1
    class Solution:
    # @param {ListNode} l1
    # @param {ListNode} l2
    # @return {ListNode}
    def mergeTwoLists(self, l1, l2):
        if l1 is None:
            return l2
        if l2 is None:
            return l1
        small, large = (l1, l2) if l1.val < l2.val else (l2, l1)
        head = small
        while != None:
            if > large.val:
      , large = large,
            small = = large
        return head

Log in to reply

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