题解 | #合并k个已排序的链表#
合并k个已排序的链表
http://www.nowcoder.com/practice/65cfde9e5b9b4cf2b6bafa5f3ef33fa6
首先是将 所有的链表的值加入到 列表中 然后进行排序 然后使用 固定头指针法则 生成一个循环体链表 返回头节点
记得处理边界问题:
    def mergeKLists(self , lists: List[ListNode]) -> ListNode:
        # write code here
        temp=[]
        for head in lists:
             while head:
                    temp.append(head.val)
                    head=head.next
        if len(temp)==0:
            return None
        temp.sort()
        data=pre=ListNode(0)
        for index ,i in enumerate(temp):
            pre.val=i
            if index!=len(temp)-1:# 处理边界问题
                pre.next=ListNode(0)
                pre=pre.next
        return data
                
 投递中国邮政储蓄银行等公司10个岗位
投递中国邮政储蓄银行等公司10个岗位
 华为工作强度 1295人发布
华为工作强度 1295人发布