LeetCode 347 Top K Frequent Elements

LeetCode 347 Top K Frequent Elements Problem

Download Code
class Solution(object):
    def topKFrequent(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: List[int]
        """
        counter = collections.Counter(nums)
        return [k for k,v in counter.most_common(k)]
        # return heapq.nlargest(k, count.keys(), key=count.get)
Download Top K Frequent Elements.py

List of all Top K Frequent Elements problems

Leetcode 347 Top K Frequent Elements problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.