class Solution:
def mergeKLists(self, lists: List[Optional[ListNode]]) -> Optional[ListNode]:
heap = []
for l in lists:
while l:
heappush(heap, l.val)
l = l.next
if not heap:
return
head = tail = ListNode(heappop(heap))
while heap:
tail.next = ListNode(heappop(heap))
tail = tail.next
return head