合并K个有序链表(采用分治法、vector排序法分别实现)

一、合并K个链表

将n个已经有序的链表,合并成一个链表,使之有序
【1】排序法实现,时间复杂度为O(KNlogKN)
【2】分治法实现,时间复杂度为O(KNlogK)

#include<iostream >
#include<vector>
#include<algorithm>
using namespace std;
struct ListNode
{
    int val;
    ListNode* next;
    ListNode(int x)
        :val(x)
        ,next(NULL)
    {}
};

//=====================使用vector进行排序=================
bool cmp(const ListNode *headA, const ListNode* headB)
{
        

猜你喜欢

转载自blog.csdn.net/dai_wen/article/details/82056124