Skip to content

Commit

Permalink
Time: 7 ms (93.62%), Space: 43.2 MB (80.87%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Amit-S-Sahu committed Dec 30, 2024
1 parent 8061c94 commit 276b3d3
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public int countGoodStrings(int low, int high, int zero, int one) {
if (zero > one) return countGoodStrings(low, high, one, zero);
int mod = (int) 1e9 + 7;

int dp[] = new int[high + 1], res = 0;
dp[0] = 1;

for (int i = 1; i <= high; i++) {
if (i >= zero) dp[i] = (dp[i] + dp[i - zero]) % mod;
if (i >= one) dp[i] = (dp[i] + dp[i - one]) % mod;
if (i >= low) res = (res + dp[i]) % mod;
}

return res;
}
}

0 comments on commit 276b3d3

Please sign in to comment.