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 969e9d4 commit cbe39c8Copy full SHA for cbe39c8
top-k-frequent-elements/ayleeee.py
@@ -0,0 +1,10 @@
1
+class Solution:
2
+ def topKFrequent(self, nums: List[int], k: int) -> List[int]:
3
+ dict_map = {}
4
+ for a in nums:
5
+ if a in dict_map:
6
+ dict_map[a] += 1
7
+ else:
8
+ dict_map[a] = 1
9
+ lst = sorted(dict_map.items(), key=lambda x: x[1], reverse=True) # 공백 수정
10
+ return [item[0] for item in lst[0:k]]
0 commit comments