[问题描述](347. Top K Frequent Elements)
只能说,调库真香,两行代码解决问题

import heapq
import collections
class Solution:
    def topKFrequent(self, nums, k):
        num_counter = collections.Counter(nums)
        return [x[0] for x in num_counter.most_common(k)]
nums = [1,1,1,2,2,3]
k = 2
print(Solution().topKFrequent(nums,k))

347. Top K Frequent Elements刷题笔记_python