/** * struct ListNode { * int val; * struct ListNode *next; * ListNode(int x) : val(x), next(nullptr) {} * }; */ class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param lists ListNode类vector * @return ListNode类 */ public: struct compare{ bool operator()(int a,int b){ return a>b; } }; ListNode* mergeKLists(vector<ListNode*>& lists) { // write code here ListNode* ans=new ListNode(-1),*ans1=ans; int minList; priority_queue<int, vector<int>, compare> setLists; for(auto i:lists){ while(i!=nullptr){ setLists.push(i->val); i=i->next; } } while(!setLists.empty()){ ans1->next=new ListNode(setLists.top()); ans1=ans1->next; setLists.pop(); } return ans->next; } };