| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 읽기
- 프로젝트
- 3줄정리
- realclass
- 파비최
- 영어공부
- 화상영어
- 30분
- 사이드
- 쓰릴오브파이트
- 매일
- Problem Solving
- FIT XR
- Writing
- 운동
- English
- 스탭퍼
- 미드시청
- 월간
- 영어원서읽기
- leetcode
- 잡생각
- 개발자
- 10분
- Daily Challenge
- 괜찮음
- 링피트
- 만화도
- 리얼 클래스
- 뭐든
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.04.04 Today's Challenge 본문
https://leetcode.com/problems/optimal-partition-of-string/
Optimal Partition of String - LeetCode
Can you solve this real interview question? Optimal Partition of String - Given a string s, partition the string into one or more substrings such that the characters in each substring are unique. That is, no letter appears in a single substring more than o
leetcode.com
탐욕법으로 풀면 되는 문제!
class Solution:
def partitionString(self, s: str) -> int:
ls = [-1] * 26
cnt = 1
ss = 0
for i in range(len(s)):
if ls[ord(s[i]) - ord('a')] >= ss:
cnt += 1
ss = i
ls[ord(s[i]) - ord('a')] = i
return cnt반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
| 2023.04.06 Today's Challenge (0) | 2023.04.06 |
|---|---|
| 2023.04.05 Today's Challenge (0) | 2023.04.05 |
| 2023.04.03 Today's Challenge (0) | 2023.04.03 |
| 2023.04.02 Today's Challenge (0) | 2023.04.02 |
| 2023.04.01 Today's Challenge (0) | 2023.04.01 |
Comments