일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- English
- 쓰릴오브파이트
- 미드시청
- 뭐든
- 30분
- leetcode
- 링피트
- Daily Challenge
- 영어원서읽기
- 만화도
- FIT XR
- 월간
- 운동
- 스탭퍼
- 매일
- 리얼 클래스
- Writing
- 프로젝트
- 괜찮음
- 읽기
- realclass
- 사이드
- 개발자
- 10분
- 영어공부
- 3줄정리
- 화상영어
- 잡생각
- Problem Solving
- 파비최
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.09.12 Today's Challenge 본문
https://leetcode.com/problems/minimum-deletions-to-make-character-frequencies-unique/
Minimum Deletions to Make Character Frequencies Unique - LeetCode
Can you solve this real interview question? Minimum Deletions to Make Character Frequencies Unique - A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of charac
leetcode.com
어제에 이어 오늘도 탐욕법으로 푸는 문제.
class Solution:
def minDeletions(self, s: str) -> int:
cnt = Counter(s)
d = 0
ufreq = set()
for c, freq in cnt.items():
while freq > 0 and freq in ufreq:
freq -= 1
d += 1
ufreq.add(freq)
return d
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.09.14 Today's Challenge (0) | 2023.09.14 |
---|---|
2023.09.13 Today's Challenge (0) | 2023.09.13 |
2023.09.11 Today's Challenge (0) | 2023.09.11 |
2023.09.10 Today's Challenge (0) | 2023.09.10 |
2023.09.09 Today's Challenge (0) | 2023.09.09 |
Comments