일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 스탭퍼
- 사이드
- 운동
- 만화도
- 영어공부
- 뭐든
- 괜찮음
- 30분
- 월간
- English
- 매일
- realclass
- 프로젝트
- 리얼 클래스
- 링피트
- FIT XR
- Problem Solving
- 개발자
- leetcode
- 쓰릴오브파이트
- 미드시청
- 10분
- 파비최
- Daily Challenge
- 3줄정리
- 읽기
- Writing
- 화상영어
- 잡생각
- 영어원서읽기
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.04.23 Today's Challenge 본문
https://leetcode.com/problems/restore-the-array/
Restore The Array - LeetCode
Can you solve this real interview question? Restore The Array - A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits s and all we know is that all integers in the array
leetcode.com
결국 DP로 푸는 문제
class Solution:
def numberOfArrays(self, s: str, k: int) -> int:
m, n = len(s), len(str(k))
mod = 10 ** 9 + 7
dp = [0] * (m+1)
def dfs(start):
if dp[start]:
return dp[start]
if start == m:
return 1
if s[start] == '0':
return 0
count = 0
for end in range(start, m):
curr_number = s[start: end+1]
if int(curr_number) > k:
break
count += dfs(end+1)
dp[start] = count % mod
return count
return dfs(0) % mod
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.04.25 Today's Challenge (0) | 2023.04.25 |
---|---|
2023.04.24 Today's Challenge (0) | 2023.04.24 |
2023.04.22 Today's Challenge (0) | 2023.04.22 |
2023.04.21 Today's Challenge (0) | 2023.04.21 |
2023.04.20 Today's Challenge (0) | 2023.04.20 |
Comments