// C++ ListNode* mergeKListsPriorityQueue(vector<ListNode*>& lists){ ListNode dummyRoot(0); auto p = &dummyRoot; auto cmp = [](ListNode* l1, ListNode* l2) { return l1->val > l2->val; }; priority_queue<ListNode*, vector<ListNode*>, decltype(cmp)> queue(cmp); for (auto i = 0; i < lists.size(); ++i) { auto l = lists[i]; if (l) { queue.push(l); } } while (!queue.empty()) { auto top = queue.top(); queue.pop(); p->next = top; p = p->next; if (top->next) { queue.push(top->next); } } return dummyRoot.next; }