mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
修复了 JavaScript 解法二,堆 pop 方法无法处理数组长度 <= 1 的边界情况的问题
This commit is contained in:
@ -405,6 +405,11 @@ class Heap {
|
|||||||
|
|
||||||
// 获取堆顶元素并移除
|
// 获取堆顶元素并移除
|
||||||
pop() {
|
pop() {
|
||||||
|
// 边界情况,只有一个元素或没有元素应直接弹出
|
||||||
|
if (this.size() <= 1) {
|
||||||
|
return this.queue.pop()
|
||||||
|
}
|
||||||
|
|
||||||
// 堆顶元素
|
// 堆顶元素
|
||||||
const out = this.queue[0];
|
const out = this.queue[0];
|
||||||
|
|
||||||
@ -608,3 +613,4 @@ impl Solution {
|
|||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user