Skip to content

Commit 610b947

Browse files
committed
301224
1 parent 73bb7fc commit 610b947

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from functools import cache
2+
from typing import List
3+
4+
# leetcode submit region begin(Prohibit modification and deletion)
5+
class Solution(object):
6+
def countGoodStrings(self, low, high, zero, one):
7+
"""
8+
:type low: int
9+
:type high: int
10+
:type zero: int
11+
:type one: int
12+
:rtype: int
13+
"""
14+
MOD = 10 ** 9 + 7
15+
@cache
16+
def go(size):
17+
if size > high:
18+
return 0
19+
ans = 0
20+
if size + zero <= high:
21+
if size + zero >= low:
22+
ans += 1
23+
ans = (ans + go(size + zero)) % MOD
24+
if size + one <= high:
25+
if size + one >= low:
26+
ans += 1
27+
ans = (ans + go(size + one)) % MOD
28+
return ans % MOD
29+
return go(0) % MOD
30+
31+
32+
# leetcode submit region end(Prohibit modification and deletion)
33+
34+
35+
class CountWaysToBuildGoodStrings(Solution):
36+
pass
37+

main.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
from leetcode.editor.en.Q1475.FinalPricesWithASpecialDiscountInAShop import FinalPricesWithASpecialDiscountInAShop
2-
from leetcode.editor.en.Q2182.ConstructStringWithRepeatLimit import ConstructStringWithRepeatLimit
3-
from leetcode.editor.en.Q2257.CountUnguardedCellsInTheGrid import CountUnguardedCellsInTheGrid
4-
from leetcode.editor.en.Q2516.TakeKOfEachCharacterFromLeftAndRight import TakeKOfEachCharacterFromLeftAndRight
5-
from leetcode.editor.en.Q2601.PrimeSubtractionOperation import PrimeSubtractionOperation
6-
from leetcode.editor.en.Q494.TargetSum import TargetSum
1+
from leetcode.editor.en.Q2466.CountWaysToBuildGoodStrings import CountWaysToBuildGoodStrings
72
from leetcode.editor.en.Q689.MaximumSumOf3NonOverlappingSubarrays import MaximumSumOf3NonOverlappingSubarrays
83

94
if __name__ == '__main__':
10-
print(MaximumSumOf3NonOverlappingSubarrays().maxSumOfThreeSubarrays([1,2,1,2,6,7,5,1], k = 2))
5+
print(CountWaysToBuildGoodStrings().countGoodStrings(low = 3, high = 3, zero = 1, one = 1))
116

0 commit comments

Comments
 (0)