| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
Tags
- FIT XR
- 개발자
- 영어공부
- 잡생각
- 뭐든
- 30분
- 10분
- 영어원서읽기
- 월간
- 파비최
- 읽기
- English
- 화상영어
- Daily Challenge
- 리얼 클래스
- 운동
- 사이드
- Writing
- Problem Solving
- realclass
- 스탭퍼
- 프로젝트
- 링피트
- 괜찮음
- 매일
- 미드시청
- 3줄정리
- 쓰릴오브파이트
- 만화도
- leetcode
Archives
- Today
- Total
파비의 매일매일 공부기록
Today's Challenge 본문
https://leetcode.com/problems/top-k-frequent-words/
Top K Frequent Words - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
오랫만에 내 손으로 풀어봄.
정렬에 대한 건 살짝 리서치를 하긴 해야했지만 ㅎㅎ;
class Solution:
def topKFrequent(self, words: List[str], k: int) -> List[str]:
d = {}
res = []
for word in words:
if not d.get(word):
d[word] = 1
else:
d[word] += 1
sd = sorted(d.items(), key=lambda item: (-item[1], item[0]))
for i in range(k):
res.append(sd[i][0])
return res반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| Today's Challenge (0) | 2022.10.21 |
|---|---|
| Today's Challenge (0) | 2022.10.20 |
| Today's Challenge (0) | 2022.10.18 |
| Today's Challenge (0) | 2022.10.17 |
| Today's Challenge (0) | 2022.10.16 |
Comments