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

 

posted @ 2019-03-21 07:09  周洋  阅读(130)  评论(0编辑  收藏  举报