diff --git a/problems/0347.前K个高频元素.md b/problems/0347.前K个高频元素.md index 34d9f82c..8a219c6a 100644 --- a/problems/0347.前K个高频元素.md +++ b/problems/0347.前K个高频元素.md @@ -405,6 +405,11 @@ class Heap { // 获取堆顶元素并移除 pop() { + // 边界情况,只有一个元素或没有元素应直接弹出 + if (this.size() <= 1) { + return this.queue.pop() + } + // 堆顶元素 const out = this.queue[0]; @@ -608,3 +613,4 @@ impl Solution { +