일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Writing
- Daily Challenge
- 미드시청
- 운동
- English
- 잡생각
- 월간
- 괜찮음
- 만화도
- leetcode
- 30분
- 영어원서읽기
- 쓰릴오브파이트
- 화상영어
- 읽기
- FIT XR
- 10분
- 사이드
- 3줄정리
- realclass
- Problem Solving
- 개발자
- 프로젝트
- 영어공부
- 스탭퍼
- 파비최
- 링피트
- 리얼 클래스
- 매일
- 뭐든
Archives
- Today
- Total
파비의 매일매일 공부기록
2023.05.13 Today's Challenge 본문
https://leetcode.com/problems/count-ways-to-build-good-strings/
Count Ways To Build Good Strings - LeetCode
Can you solve this real interview question? Count Ways To Build Good Strings - Given the integers zero, one, low, and high, we can construct a string by starting with an empty string, and then at each step perform either of the following: * Append the char
leetcode.com
오늘도 DP.
보이는 것에 비해 꽤나 간단한 코드로 끝이 나는 문제.
class Solution:
def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int:
dp = [1] + [0] * (high)
mod = 10 ** 9 + 7
for end in range(1, high + 1):
if end >= zero:
dp[end] += dp[end - zero]
if end >= one:
dp[end] += dp[end - one]
dp[end] %= mod
return sum(dp[low : high+1]) % mod
반응형
'Problem Solving > LeetCode' 카테고리의 다른 글
2023.05.15 Today's Challenge (1) | 2023.05.15 |
---|---|
2023.05.14 Today's Challenge (0) | 2023.05.14 |
2023.05.12 Today's Challenge (0) | 2023.05.12 |
2023.05.11 Today's Challenge (0) | 2023.05.11 |
2023.05.10 Today's Challenge (0) | 2023.05.10 |
Comments