# Definition for singly-linked list.
# class ListNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.next = None

class Solution(object):
    def mergeKLists(self, lists):
        """
        :type lists: List[ListNode]
        :rtype: ListNode
        """
        heap=[]
        for node in lists:
            if node != None:
                heap.append((node.val,node))
        heapq.heapify(heap)
        head=ListNode(0)
        curr=head
        while heap:
            pop=heapq.heappop(heap)
            curr.next=pop[1]
            curr=curr.next
            if pop[1].next:
                heapq.heappush(heap,(pop[1].next.val,pop[1].next))
        return head.next

 

相关文章:

  • 2021-10-16
  • 2022-02-21
  • 2021-10-30
  • 2021-12-26
  • 2021-12-15
  • 2021-11-18
猜你喜欢
  • 2021-07-07
  • 2021-07-29
  • 2021-08-27
  • 2021-06-21
  • 2022-01-24
  • 2021-09-20
  • 2021-11-16
相关资源
相似解决方案