Skip to content

Commit f0db96a

Browse files
committed
feat: 347. Top K Frequent Elements
1 parent f54580f commit f0db96a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

top-k-frequent-elements/HodaeSsi.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
class Solution:
4+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
5+
dict = {}
6+
for num in nums:
7+
dict[num] = dict.get(num, 0) + 1
8+
9+
return sorted(dict.keys(), key=lambda x: dict[x], reverse=True)[:k]
10+

0 commit comments

Comments
 (0)