diff --git "a/\345\244\232\350\257\255\350\250\200\350\247\243\346\263\225\344\273\243\347\240\201/solution_code.md" "b/\345\244\232\350\257\255\350\250\200\350\247\243\346\263\225\344\273\243\347\240\201/solution_code.md" index 4a577d5958..16fd4de1ac 100644 --- "a/\345\244\232\350\257\255\350\250\200\350\247\243\346\263\225\344\273\243\347\240\201/solution_code.md" +++ "b/\345\244\232\350\257\255\350\250\200\350\247\243\346\263\225\344\273\243\347\240\201/solution_code.md" @@ -67158,20 +67158,21 @@ var mergeKLists = function(lists) { var dummy = new ListNode(-1); var p = dummy; // 优先级队列,最小堆 - var pq = new PriorityQueue( - lists.length, (a, b) => (a.val - b.val)); + var pq = new PriorityQueue({ + compare: (a, b) => (a.val - b.val) + }); // 将 k 个链表的头结点加入最小堆 for (var head of lists) { if (head != null) - pq.add(head); + pq.enqueue(head); } while (!pq.isEmpty()) { // 获取最小节点,接到结果链表中 - var node = pq.poll(); + var node = pq.dequeue(); p.next = node; if (node.next != null) { - pq.add(node.next); + pq.enqueue(node.next); } // p 指针不断前进 p = p.next;