Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions top-k-frequent-elements/do-heewan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Solution(object):
def topKFrequent(self, nums, k):
count = {}
result = []

for i in nums:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collections.Counter를 쓰면 더 간단히 처리 가능합니다

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 피드백 감사합니다

if i not in count:
count[i] = 1
else:
count[i] += 1

count = sorted(count.items(), key=lambda x : x[1], reverse=True)

return [item[0] for item in count[:k]]

Loading