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 0d6efd4 commit 0711835Copy full SHA for 0711835
top-k-frequent-elements/Sung-Heon.py
@@ -0,0 +1,9 @@
1
+class Solution:
2
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3
+ temp = {}
4
+ for i in nums:
5
+ if temp.get(i):
6
+ temp[i] += 1
7
+ else:
8
+ temp[i] = 1
9
+ return [key for key, value in sorted(temp.items(), key=lambda x: x[1],reverse=True)][:k]
0 commit comments