From 1c390b3562b03be7a24933455b76a9187996ff72 Mon Sep 17 00:00:00 2001 From: xqsrpanz Date: Fri, 26 Apr 2024 18:01:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=20JavaScript=20?= =?UTF-8?q?=E8=A7=A3=E6=B3=95=E4=BA=8C=EF=BC=8C=E5=A0=86=20pop=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=97=A0=E6=B3=95=E5=A4=84=E7=90=86=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=20<=3D=201=20=E7=9A=84=E8=BE=B9=E7=95=8C?= =?UTF-8?q?=E6=83=85=E5=86=B5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0347.前K个高频元素.md | 6 ++++++ 1 file changed, 6 insertions(+) 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 { +