# Definition for singly-linked list. # class ListNode(object): # def __init__(self, x): # self.val = x # self.next = None class Solution(object): def mergeKLists(self, lists): """ :type lists: List[ListNode] :rtype: ListNode """ if not lists: return #暴力法 r=[] for i in range(len(lists)): if not lists[i]: continue head=lists[i] p=head while p: r.append(p.val) p=p.next if not r: return r.sort() head=ListNode(r[0]) p=head for j in range(1,len(r)): p.next=ListNode(r[j]) p=p.next return head
原文:https://www.cnblogs.com/taoyuxin/p/11773559.html