给定一个非空的整数数组,返回其中出现频率前 k 高的元素。
法1) 使用 Counter 的most_common(k) 方法
class Solution:
def topKFrequent(self, nums, k):
count = collections.Counter(nums)
return heap.nlargest(k,count.keys(),key = count.get())
原文:https://www.cnblogs.com/ChevisZhang/p/12540681.html