Merge pull request #1783 from ZerenZhang2022/patch-1

Update 0347.前K个高频元素.md
This commit is contained in:
程序员Carl
2022-12-11 10:10:25 +08:00
committed by GitHub

View File

@ -204,7 +204,7 @@ class Solution:
#定义一个小顶堆大小为k
pri_que = [] #小顶堆
#用固定大小为k的小顶堆所有频率的数值
#用固定大小为k的小顶堆所有频率的数值
for key, freq in map_.items():
heapq.heappush(pri_que, (freq, key))
if len(pri_que) > k: #如果堆的大小大于了K则队列弹出保证堆的大小一直为k