Skip to content

Commit 291e8cd

Browse files
authored
fix(javascript): merge-k-sorted-lists (#1575)
1 parent 9968397 commit 291e8cd

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

多语言解法代码/solution_code.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -39379,20 +39379,21 @@ var mergeKLists = function(lists) {
3937939379
let dummy = new ListNode(-1);
3938039380
let p = dummy;
3938139381
// 优先级队列,最小堆
39382-
let pq = new PriorityQueue(
39383-
lists.length, (a, b) => (a.val - b.val));
39382+
let pq = new PriorityQueue({
39383+
compare: (a, b) => (a.val - b.val)
39384+
});
3938439385
// 将 k 个链表的头结点加入最小堆
3938539386
for (let head of lists) {
3938639387
if (head != null)
39387-
pq.add(head);
39388+
pq.enqueue(head);
3938839389
}
3938939390

3939039391
while (!pq.isEmpty()) {
3939139392
// 获取最小节点,接到结果链表中
39392-
let node = pq.poll();
39393+
let node = pq.dequeue();
3939339394
p.next = node;
3939439395
if (node.next != null) {
39395-
pq.add(node.next);
39396+
pq.enqueue(node.next);
3939639397
}
3939739398
// p 指针不断前进
3939839399
p = p.next;

0 commit comments

Comments
 (0)