일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 30분
- 개발자
- Problem Solving
- 만화도
- leetcode
- 매일
- 미드시청
- 3줄정리
- 영어원서읽기
- Daily Challenge
- 스탭퍼
- 10분
- 화상영어
- 뭐든
- 사이드
- 잡생각
- Writing
- 링피트
- 월간
- English
- 운동
- realclass
- 영어공부
- 프로젝트
- 읽기
- 파비최
- FIT XR
- 리얼 클래스
- 쓰릴오브파이트
- 괜찮음
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