# 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:
if lists==[]:return None
result=ListNode(0)
prehead=result
length=len(lists)
while lists:
temp=[]
for i in lists:
if i!=None:
temp.append(i.val)
else:
temp.append(10000)
#print(temp)
if temp!=[10000]*length:
temp_index=temp.index(min(temp))
prehead.next=lists[temp_index]
lists[temp_index]=lists[temp_index].next
prehead=prehead.next
#print(prehead.val)
else:
break
return result.next
#p
leetcode刷题python之合并K个排序链表
最新推荐文章于 2020-12-23 12:06:54 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)