/**
* struct ListNode {
* int val;
* struct ListNode *next;
* ListNode(int x) : val(x), next(nullptr) {}
* };
*/
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param pHead1 ListNode类
* @param pHead2 ListNode类
* @return ListNode类
*/
ListNode* Merge(ListNode* pHead1, ListNode* pHead2) {
// write code here
priority_queue<int,vector<int>,greater<int>> pq;
if(!pHead1&&!pHead2) return nullptr;
while(pHead1){
pq.push(pHead1->val);
pHead1=pHead1->next;
}
while(pHead2){
pq.push(pHead2->val);
pHead2=pHead2->next;
}
ListNode* pHead=new ListNode(0);
ListNode* res=pHead;
while(!pq.empty()){
pHead->val=pq.top();pq.pop();
if(pq.empty()) break;
ListNode* temp=new ListNode(0);
pHead->next=temp;
pHead=temp;
}
return res;
}
};