Skip to content

Commit 7123351

Browse files
committed
top-k-frequent solution
1 parent 2831e27 commit 7123351

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

top-k-frequent-elements/yayyz.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from collections import Counter
2+
import heapq
3+
4+
class Solution:
5+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
6+
count_dict = Counter(nums)
7+
return heapq.nlargest(k, count_dict.keys(), key=count_dict.get)

0 commit comments

Comments
 (0)