We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent decee37 commit a3e7172Copy full SHA for a3e7172
top-k-frequent-elements/hodaessi.py
@@ -0,0 +1,9 @@
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]
0 commit comments