일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 프로젝트
- 파비최
- 영어원서읽기
- 스탭퍼
- 리얼 클래스
- 잡생각
- Daily Challenge
- 미드시청
- leetcode
- Writing
- 3줄정리
- 링피트
- 10분
- 뭐든
- 쓰릴오브파이트
- realclass
- 월간
- 매일
- FIT XR
- English
- 만화도
- 영어공부
- 읽기
- 괜찮음
- 화상영어
- Problem Solving
- 운동
- 사이드
- 30분
- 개발자
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.07.30 Today's Challenge 본문
https://leetcode.com/problems/strange-printer/
Strange Printer - LeetCode
Can you solve this real interview question? Strange Printer - There is a strange printer with the following two special properties: * The printer can only print a sequence of the same character each time. * At each turn, the printer can print new character
leetcode.com
오랫만에 릿코드 고고싱
class Solution:
def strangePrinter(self, s: str) -> int:
n = len(s)
dp = [[n] * n for _ in range(n)]
for length in range(1, n+1):
for left in range(n-length+1):
right = left + length - 1
j = -1
for i in range(left, right):
if s[i] != s[right] and j == -1:
j = i
if j != -1:
dp[left][right] = min(dp[left][right], 1+dp[j][i]+dp[i+1][right])
if j== -1:
dp[left][right] = 0
return dp[0][n-1] + 1
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.08.01 Today's Challenge (0) | 2023.08.01 |
---|---|
2023.07.31 Today's Challenge (0) | 2023.07.31 |
2023.07.29 Today's Challenge (0) | 2023.07.29 |
2023.07.28 Today's Challenge (0) | 2023.07.28 |
2023.07.27 Today's Challenge (0) | 2023.07.27 |
Comments