1
var mergeKLists = function (lists) {2
// Use min heap to keep track of the smallest node in constant time.3
// Enqueue and dequeue will be log(k) where k is the # of lists4
// b/c we only need to keep track of the next node for each list6
const minHeap = new MinPriorityQueue({ priority: (item) => item.val });8
for (let head of lists) {9
if (head) minHeap.enqueue(head);12
// Create tempHead that we initiate the new list with13
// Final list will start at tempHead.next14
const tempHead = new ListNode();17
while (!minHeap.isEmpty()) {18
const { val, next } = minHeap.dequeue().element;19
curr.next = new ListNode(val);22
if (next) minHeap.enqueue(next);