| 31 | import heapq |
| 32 | |
| 33 | class 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 |
nothing calls this directly
no outgoing calls
no test coverage detected