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]]

 

相关文章: