Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def topKFrequent(self, nums: List[int], k: int) -> List[int]:
- from collections import Counter
- hashmap = Counter(nums)
- freqs = [[key, value] for key, value in hashmap.items()]
- freqs.sort(key = lambda x : x[1], reverse = True)
- return [x[0] for x in freqs[:k]]
Advertisement
Add Comment
Please, Sign In to add comment