class Solution:
def mergeKLists(self, lists: List[Optional[ListNode]]) -> Optional[ListNode]:
dummy = ListNode()
cur = dummy
def __lt__(self, other):
return self.val < other.val
ListNode.__lt__ = __lt__
h = []
for i in lists:
if i:
heapq.heappush(h, i)
while h:
node = heapq.heappop(h)
cur.next = ListNode(node.val)
cur = cur.next
if node.next:
heapq.heappush(h, node.next)
return dummy.next
02-25
708
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-19
891
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-07
242
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-18
534
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
11-21
532
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-14