cs: add «2466. Count Ways To Build Good Strings»

URL:	https://leetcode.com/problems/count-ways-to-build-good-strings/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-12-30 16:30:54 +01:00
parent 97906d6431
commit 5cc859c6b4
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,28 @@
public class Solution {
private static readonly int MOD = 1_000_000_007;
public int CountGoodStrings(int low, int high, int zero, int one) {
var dp = new int[high + 1];
dp[0] = 1;
for (var end = 1; end <= high; ++end) {
if (end >= zero) {
dp[end] += dp[end - zero];
}
if (end >= one) {
dp[end] += dp[end - one];
}
dp[end] %= MOD;
}
var good = 0;
for (var length = low; length <= high; ++length) {
good += dp[length];
good %= MOD;
}
return good;
}
}