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.pyLeetcode 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.