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 e594a4b commit 0b11f20Copy full SHA for 0b11f20
top-k-frequent-elements/HYUNAHKO.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3
+ value_dict = {}
4
+
5
+ for num in nums:
6
+ if num in value_dict:
7
+ value_dict[num] += 1
8
+ else:
9
+ value_dict[num] = 1
10
11
+ sorted_items = sorted(value_dict.items(), key=lambda x: x[1], reverse=True)
12
13
+ return [key for key, value in sorted_items[:k]]
0 commit comments