Can't believe this one can get an AC


  • 0
    W
    class Solution(object):
    def mergeTwoLists(self, l1, l2):
        """
        :type l1: ListNode
        :type l2: ListNode
        :rtype: ListNode
        """
        if not l1:
            return l2
        if not l2:
            return l1
        
        temp = []
        tmp = l1
        while tmp:
            temp.append(tmp.val)
            tmp = tmp.next
        tmp = l2
        while tmp:
            temp.append(tmp.val)
            tmp = tmp.next
        
        temp.sort()
        ans = ListNode(None)
        tmp = ans
        for i in temp:
            tmp.next = ListNode(i)
            tmp = tmp.next
        
        return ans.next

Log in to reply
 

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