Skip to content

Commit aefeeaa

Browse files
committed
https://leetcode.cn/problems/count-ways-to-build-good-string
1 parent b56dba5 commit aefeeaa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/count-ways-to-build-good-string
49+
4850
https://leetcode.cn/problems/number-of-distinct-averages
4951

5052
https://leetcode.cn/problems/custom-sort-string
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function countGoodStrings(
2+
low: number,
3+
high: number,
4+
zero: number,
5+
one: number,
6+
): number {
7+
const dp: number[] = Array(high + 1).fill(0);
8+
dp[0] = 1;
9+
const mod = 1e9 + 7;
10+
let ans = 0;
11+
for (let i = 0; i <= high; i++) {
12+
if (i >= zero) dp[i] += dp[i - zero];
13+
if (i >= one) dp[i] += dp[i - one];
14+
dp[i] %= mod;
15+
if (i >= low) ans = (ans + dp[i]) % mod;
16+
}
17+
return ans;
18+
}
19+
export default countGoodStrings;

0 commit comments

Comments
 (0)