Skip to content

Commit cbe39c8

Browse files
committed
top k frequent elements solution
1 parent 969e9d4 commit cbe39c8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

top-k-frequent-elements/ayleeee.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)