Skip to content

Commit

Permalink
Create 13 May | 2466. Count Ways To Build Good Strings.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
SumitPareek2401 authored May 13, 2023
1 parent 94bc7d2 commit bff189d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions 13 May | 2466. Count Ways To Build Good Strings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
int mod = 1e9+7;
int solve(int target, int one, int zero, vector<int> &dp){
if(target == 0)
return 1;

if(target < 0)
return 0;

if(dp[target] != -1) return dp[target];
long long sum;
sum = solve(target-one, one, zero, dp) + solve(target-zero, one, zero, dp);
return dp[target] = sum%mod;
}
public:
int countGoodStrings(int low, int high, int zero, int one) {
int ans = 0;
vector<int> dp(high+1, -1);

for(int i = low; i <= high; i++){
ans = ((ans%mod) + solve(i, one, zero, dp))%mod;
}
return ans;
}
};

0 comments on commit bff189d

Please sign in to comment.