"""
https://leetcode-cn.com/problems/merge-k-sorted-lists/solution/he-bing-kge-pai-xu-lian-biao-by-leetcode/
思路:还是以暴力遍历为主,先将链表->列表->列表.排序->新链表
1.新建一个空list,用以存储链表值,sortList存储排序后列表值
2.新建两个ListNode:head和dummy
2.1:head用以最后链表头的返回
2.2:dummy用以创建新链表
3.遍历链表,将值记录list;列表排序
4.生成新链表
"""
class Solution:
def mergeKLists(self, lists: List[ListNode]):
curList=[]
head=ListNode(0)
dummy=head
for ln in lists: #循环List中的ListNode
while ln: #循环ListNode中的node
curList.append(ln.val)
ln=ln.next
sortList=sorted(curList)
for num in sortList:
dummy.next=ListNode(num)
dummy=dummy.next
return head.next
来源:oschina
链接:https://my.oschina.net/tedzheng/blog/3213823