/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
struct Mycompare
{
bool operator()(ListNode* a, ListNode* b) {
return a->val > b->val;
}
};
ListNode *mergeKLists(vector<ListNode *> &lists) {
// auto compare=[](ListNode*&a,ListNode*&b)
// {
// return a->val>b->val;
// };
priority_queue<ListNode*,vector<ListNode *>,Mycompare> que;
for(int i=0;i<lists.size();i++)
{
if(lists[i]) que.push(lists[i]);
}
ListNode* head=new ListNode(0);
head->next=NULL;
ListNode* tail=head;//尾这指针
while(!que.empty())
{
ListNode* temp=que.top();
ListNode* t=temp->next;
que.pop();
temp->next=tail->next;
tail->next=temp;
tail=temp;
if(t)
{
que.push(t);
cout<<"K";
}
}
return head->next;
}
};