Python short and concise

  • 0
    from heapq import *
    class Solution(object):
        def mergeKLists(self, lists):
            :type lists: List[ListNode]
            :rtype: ListNode
            head = p = ListNode(-1)
            heap = []
            for i in lists:
                if i :  heappush(heap,(i.val,i))
            while heap :
                small = heappop(heap)[1]
       = small
                if heappush(heap,(,
                p = small
       = None

Log in to reply

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