smj007

Untitled

Jun 18th, 2022 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. class Solution:
  2.     def topKFrequent(self, nums: List[int], k: int) -> List[int]:
  3.        
  4.         from collections import Counter
  5.         hashmap = Counter(nums)
  6.  
  7.         freqs = [[key, value] for key, value in hashmap.items()]  
  8.         freqs.sort(key = lambda x : x[1], reverse = True)
  9.        
  10.         return [x[0] for x in freqs[:k]]
Advertisement
Add Comment
Please, Sign In to add comment