My python solution with recursion

  • 1
    class Solution(object):
        def mergeTwoLists(self, l1, l2):
            :type l1: ListNode
            :type l2: ListNode
            :rtype: ListNode
            if not l1 or not l2: # If l1 or l2 is exhausted, return the other
                return l1 or l2
            if l1.val < l2.val:
       = self.mergeTwoLists(, l2)
                return l1
       = self.mergeTwoLists(l1,
                return l2

Log in to reply

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