diff --git a/solution/0600-0699/0630.Course Schedule III/README.md b/solution/0600-0699/0630.Course Schedule III/README.md index 6375a17781381..0892c7c3ea024 100644 --- a/solution/0600-0699/0630.Course Schedule III/README.md +++ b/solution/0600-0699/0630.Course Schedule III/README.md @@ -179,13 +179,13 @@ func (h *hp) pop() int { return heap.Pop(h).(int) } ```ts function scheduleCourse(courses: number[][]): number { courses.sort((a, b) => a[1] - b[1]); - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); let s = 0; for (const [duration, last] of courses) { pq.enqueue(duration); s += duration; while (s > last) { - s -= pq.dequeue().element; + s -= pq.dequeue(); } } return pq.size(); diff --git a/solution/0600-0699/0630.Course Schedule III/README_EN.md b/solution/0600-0699/0630.Course Schedule III/README_EN.md index 635e4695af275..c62bec88ced90 100644 --- a/solution/0600-0699/0630.Course Schedule III/README_EN.md +++ b/solution/0600-0699/0630.Course Schedule III/README_EN.md @@ -170,13 +170,13 @@ func (h *hp) pop() int { return heap.Pop(h).(int) } ```ts function scheduleCourse(courses: number[][]): number { courses.sort((a, b) => a[1] - b[1]); - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); let s = 0; for (const [duration, last] of courses) { pq.enqueue(duration); s += duration; while (s > last) { - s -= pq.dequeue().element; + s -= pq.dequeue(); } } return pq.size(); diff --git a/solution/0600-0699/0630.Course Schedule III/Solution.ts b/solution/0600-0699/0630.Course Schedule III/Solution.ts index cf53fa353f7fb..fa2048b5b649b 100644 --- a/solution/0600-0699/0630.Course Schedule III/Solution.ts +++ b/solution/0600-0699/0630.Course Schedule III/Solution.ts @@ -1,12 +1,12 @@ function scheduleCourse(courses: number[][]): number { courses.sort((a, b) => a[1] - b[1]); - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); let s = 0; for (const [duration, last] of courses) { pq.enqueue(duration); s += duration; while (s > last) { - s -= pq.dequeue().element; + s -= pq.dequeue(); } } return pq.size(); diff --git a/solution/0900-0999/0973.K Closest Points to Origin/README.md b/solution/0900-0999/0973.K Closest Points to Origin/README.md index c2619b2a8acc1..b11686cc6a7ac 100644 --- a/solution/0900-0999/0973.K Closest Points to Origin/README.md +++ b/solution/0900-0999/0973.K Closest Points to Origin/README.md @@ -259,15 +259,15 @@ func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; retur ```ts function kClosest(points: number[][], k: number): number[][] { - const maxQ = new MaxPriorityQueue(); + const maxQ = new MaxPriorityQueue<{ point: number[]; dist: number }>(entry => entry.dist); for (const [x, y] of points) { const dist = x * x + y * y; - maxQ.enqueue([x, y], dist); + maxQ.enqueue({ point: [x, y], dist }); if (maxQ.size() > k) { maxQ.dequeue(); } } - return maxQ.toArray().map(item => item.element); + return maxQ.toArray().map(entry => entry.point); } ``` diff --git a/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md b/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md index 5a6704413aee5..2335041d3f46c 100644 --- a/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md +++ b/solution/0900-0999/0973.K Closest Points to Origin/README_EN.md @@ -255,15 +255,15 @@ func (h *hp) Pop() any { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; retur ```ts function kClosest(points: number[][], k: number): number[][] { - const maxQ = new MaxPriorityQueue(); + const maxQ = new MaxPriorityQueue<{ point: number[]; dist: number }>(entry => entry.dist); for (const [x, y] of points) { const dist = x * x + y * y; - maxQ.enqueue([x, y], dist); + maxQ.enqueue({ point: [x, y], dist }); if (maxQ.size() > k) { maxQ.dequeue(); } } - return maxQ.toArray().map(item => item.element); + return maxQ.toArray().map(entry => entry.point); } ``` diff --git a/solution/0900-0999/0973.K Closest Points to Origin/Solution2.ts b/solution/0900-0999/0973.K Closest Points to Origin/Solution2.ts index afeb1c9d648f6..9c7b62a6e4027 100644 --- a/solution/0900-0999/0973.K Closest Points to Origin/Solution2.ts +++ b/solution/0900-0999/0973.K Closest Points to Origin/Solution2.ts @@ -1,11 +1,11 @@ function kClosest(points: number[][], k: number): number[][] { - const maxQ = new MaxPriorityQueue(); + const maxQ = new MaxPriorityQueue<{ point: number[]; dist: number }>(entry => entry.dist); for (const [x, y] of points) { const dist = x * x + y * y; - maxQ.enqueue([x, y], dist); + maxQ.enqueue({ point: [x, y], dist }); if (maxQ.size() > k) { maxQ.dequeue(); } } - return maxQ.toArray().map(item => item.element); + return maxQ.toArray().map(entry => entry.point); } diff --git a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md index de6ec8f6b68bf..347d8989c2680 100644 --- a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md +++ b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README.md @@ -180,15 +180,14 @@ func (h *hp) pop() int { return heap.Pop(h).(int) } ```ts function minStoneSum(piles: number[], k: number): number { - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); for (const x of piles) { pq.enqueue(x); } while (k--) { - pq.enqueue((pq.dequeue().element + 1) >> 1); + pq.enqueue((pq.dequeue() + 1) >> 1); } - - return pq.toArray().reduce((a, b) => a + b.element, 0); + return pq.toArray().reduce((a, b) => a + b, 0); } ``` diff --git a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md index cc0e8df44b0fe..a02d5325c4441 100644 --- a/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md +++ b/solution/1900-1999/1962.Remove Stones to Minimize the Total/README_EN.md @@ -178,15 +178,14 @@ func (h *hp) pop() int { return heap.Pop(h).(int) } ```ts function minStoneSum(piles: number[], k: number): number { - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); for (const x of piles) { pq.enqueue(x); } while (k--) { - pq.enqueue((pq.dequeue().element + 1) >> 1); + pq.enqueue((pq.dequeue() + 1) >> 1); } - - return pq.toArray().reduce((a, b) => a + b.element, 0); + return pq.toArray().reduce((a, b) => a + b, 0); } ``` diff --git a/solution/1900-1999/1962.Remove Stones to Minimize the Total/Solution.ts b/solution/1900-1999/1962.Remove Stones to Minimize the Total/Solution.ts index b15b74422286e..3b211ba768acb 100644 --- a/solution/1900-1999/1962.Remove Stones to Minimize the Total/Solution.ts +++ b/solution/1900-1999/1962.Remove Stones to Minimize the Total/Solution.ts @@ -1,11 +1,10 @@ function minStoneSum(piles: number[], k: number): number { - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); for (const x of piles) { pq.enqueue(x); } while (k--) { - pq.enqueue((pq.dequeue().element + 1) >> 1); + pq.enqueue((pq.dequeue() + 1) >> 1); } - - return pq.toArray().reduce((a, b) => a + b.element, 0); + return pq.toArray().reduce((a, b) => a + b, 0); } diff --git a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md index 3c77aadedc860..1e467f4da77d2 100644 --- a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md +++ b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README.md @@ -244,14 +244,14 @@ function minLengthAfterRemovals(nums: number[]): number { for (const x of nums) { cnt.set(x, (cnt.get(x) ?? 0) + 1); } - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); for (const [_, v] of cnt) { pq.enqueue(v); } let ans = nums.length; while (pq.size() > 1) { - let x = pq.dequeue().element; - let y = pq.dequeue().element; + let x = pq.dequeue(); + let y = pq.dequeue(); if (--x > 0) { pq.enqueue(x); } diff --git a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md index 8e57a31d40058..6b4595c4100a7 100644 --- a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md +++ b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/README_EN.md @@ -242,14 +242,14 @@ function minLengthAfterRemovals(nums: number[]): number { for (const x of nums) { cnt.set(x, (cnt.get(x) ?? 0) + 1); } - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); for (const [_, v] of cnt) { pq.enqueue(v); } let ans = nums.length; while (pq.size() > 1) { - let x = pq.dequeue().element; - let y = pq.dequeue().element; + let x = pq.dequeue(); + let y = pq.dequeue(); if (--x > 0) { pq.enqueue(x); } diff --git a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/Solution.ts b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/Solution.ts index 02d365ead29b2..0ac90a284c272 100644 --- a/solution/2800-2899/2856.Minimum Array Length After Pair Removals/Solution.ts +++ b/solution/2800-2899/2856.Minimum Array Length After Pair Removals/Solution.ts @@ -3,14 +3,14 @@ function minLengthAfterRemovals(nums: number[]): number { for (const x of nums) { cnt.set(x, (cnt.get(x) ?? 0) + 1); } - const pq = new MaxPriorityQueue(); + const pq = new MaxPriorityQueue(); for (const [_, v] of cnt) { pq.enqueue(v); } let ans = nums.length; while (pq.size() > 1) { - let x = pq.dequeue().element; - let y = pq.dequeue().element; + let x = pq.dequeue(); + let y = pq.dequeue(); if (--x > 0) { pq.enqueue(x); }