一、合并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)
{