标签:new lis 内存 amp cto clu auto next using
2020.08.05
1、多线程
2、IPC、共享内存
3、bind
4、合并n个有序链表 (力扣原题 使用最小堆会快一些)
#include <queue>
using namespace std;
struct ListNode {
int val;
ListNode* next;
ListNode(int x) : val(x), next(NULL) {}
};
class Solution {
struct cmp {
bool operator() (ListNode* a, ListNode* b) {
return a->val > b->val;
}
};
ListNode* mergeKLists(vector<ListNode*>& lists) {
priority_queue<ListNode*, vector<ListNode*>, cmp> pri;
for (auto &elem : lists) {
if (elem) {
pri.push(elem);
}
}
ListNode* head = new ListNode(0);
ListNode* pre = head;
while(!pri.empty()) {
pre->next = pri.top();
ListNode* tmp = pri.top()->next;
pri.pop();
if (tmp) {
pri.push(tmp);
}
pre = pre->next;
}
pre = head->next;
delete head;
return pre;
};
};
标签:new lis 内存 amp cto clu auto next using
原文地址:https://www.cnblogs.com/xiaohaigegede/p/13520225.html