Skip to content

Commit 6ab0783

Browse files
committed
<source>count-ways-to-build-good-string</source>
1 parent aefeeaa commit 6ab0783

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.github.masx200.leetcode_test.count_ways_to_build_good_string
2+
3+
const val mod = 1e9 + 7;
4+
5+
class Solution {
6+
fun countGoodStrings(low: Int, high: Int, zero: Int, one: Int): Int {
7+
val dp = IntArray(high + 1) { 0 }
8+
dp[0] = 1
9+
var ans = 0
10+
for (i in 1..high) {
11+
if (i >= zero) dp[i] += dp[i - zero];
12+
if (i >= one) dp[i] += dp[i - one];
13+
dp[i] = (dp[i] % mod).toInt();
14+
if (i >= low) ans = ((ans + dp[i]) % mod).toInt();
15+
}
16+
return ans;
17+
}
18+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
<source>reveal-cards-in-increasing-order</source>
102102
<source>serialize-and-deserialize-binary-tree</source>
103103
<source>three-in-one-lcci</source>
104+
<source>count-ways-to-build-good-string</source>
104105
</sourceDirs>
105106
</configuration>
106107
</execution>

0 commit comments

Comments
 (0)