Then, using it is a matter of running the linked lists through it:
xxxxxxxxxx
16
let pq = new PriorityQueue();
for (let list of arrOfLists) {
if (list) {
let currentNode = list;
pq.insert(currentNode.val);
​
// process the rest of the list
while (currentNode.next) {
pq.insert(currentNode.next.val);
currentNode = currentNode.next;
}
}
}
​
// returning this will return the head of the priority queue linked list result
return pq.first || [];
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment