题目描述(困难难度)
python 代码
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, x):
# self.val = x
# self.next = None
class Solution:
def mergeKLists(self, lists: List[ListNode]) -> ListNode:
p = ListNode(-1)
tem = p
a = []
for l in lists:
while l:
a.append(l.val)
l = l.next
a.sort()
for j in a:
tem.next = ListNode(j)
tem = tem.next
return p.next
if __name__ == '__main__':
s = Solution()
res = s.mergeKLists([1->4->5,1->3->4,2->6])
print(res)