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 12e62d0 commit 8fa2c60Copy full SHA for 8fa2c60
1 file changed
top-k-frequent-elements/hyeri0903.py
@@ -0,0 +1,12 @@
1
+class Solution:
2
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3
+ table = {}
4
+ for n in nums:
5
+ if n in table:
6
+ table[n] += 1
7
+ else:
8
+ table[n] = 1
9
+ sorted_table = sorted(table.items(), key=lambda x:x[1], reverse = True)
10
+
11
+ return [ key for key, freq in sorted_table[:k]]
12
0 commit comments