Leetcode 347. Top K Frequent Elements

class Solution(object):
    def topKFrequent(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: List[int]
        """
        count=collections.Counter(nums)
        count=sorted(count.items(),key=lambda x:x[1],reverse=True)
        return [v for v,num in count[:k]]
原文地址:https://www.cnblogs.com/zywscq/p/10569253.html