일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- leetcode
- Daily Challenge
- 괜찮음
- 영어원서읽기
- Problem Solving
- 리얼 클래스
- 화상영어
- 파비최
- realclass
- 영어공부
- 3줄정리
- FIT XR
- 미드시청
- 링피트
- English
- 월간
- 매일
- 쓰릴오브파이트
- 운동
- 스탭퍼
- 뭐든
- 10분
- 프로젝트
- 사이드
- Writing
- 읽기
- 잡생각
- 개발자
- 30분
- 만화도
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.12.05 Today's Challenge 본문
해쉬맵 형태로 푸는 법 말고
좀 더 쉬운 방법은 없을까..
class Solution:
def countCharacters(self, words: List[str], chars: str) -> int:
cnt = [0] * 26
for c in chars:
cnt[ord(c) - ord('a')] += 1
ans = 0
for word in words:
word_cnt = [0] * 26
for c in word:
word_cnt[ord(c) - ord('a')] += 1
is_ok = True
for i in range(26):
if cnt[i] < word_cnt[i]:
is_ok = False
break
if is_ok:
ans += len(word)
return ans
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.12.07 Today's Challenge (0) | 2023.12.07 |
---|---|
2023.12.06 Today's Challenge (0) | 2023.12.06 |
2023.12.04 Today's Challenge (1) | 2023.12.04 |
2023.12.03 Today's Challenge (0) | 2023.12.03 |
2023.12.02 Today's Challenge (1) | 2023.12.02 |
Comments