MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Heap/MergeKSortedLists.py:33–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31import heapq
32
33class Solution(object):
34 def mergeKLists(self, lists):
35 """
36 :type lists: List[ListNode]
37 :rtype: ListNode
38 """
39 a = []
40
41 heapq.heapify(a)
42
43 for i in lists:
44 while i:
45 heapq.heappush(a, i.val)
46 i = i.next
47 if not a:
48 return None
49
50 root = ListNode(heapq.heappop(a))
51 head = root
52
53 while a:
54 root.next = ListNode(heapq.heappop(a))
55 root = root.next
56
57 return head
58

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected