Count Ways To Build Good Strings

by atalaykutlay

Solution to Leetcode problem Count Ways To Build Good Strings in C++

Count Ways To Build Good Strings
1class Solution {
2public:
3    int countGoodStrings(int low, int high, int zero, int one) {
4         int dp[high+1];
5    memset(dp, 0, sizeof(dp));
6    dp[0]=1;
7    int ans=0;
8    for(int i=1;i<=high;i++){
9        dp[i] = ((i-zero>=0 ? dp[i-zero]:0)+(i-one>=0 ? dp[i-one]:0))%1000000007;
10        if(i>=low){
11            ans = (ans+dp[i])%1000000007;
12        }
13    }
14    return ans;
15    }
16};

Share

Share
Video
A cool 10 sec video.
Share
Detailed
Title, description, and syntax highlighted code.
Share
Simple
Syntax highlighted code with gradient background colored presentation.

Comments

It looks like there is no comment for this snippet. Leave the first one!
You need to login to send a comment.

Similar Snippets

Fast Inverse Square Root
Fast Inverse Square Root

The legendary fast inverse square root implementation from Quake III Arena source code with the original comment text.

Language: cpp20 months ago
Q_rsqrt
Q_rsqrt

The legendary fast inverse square root implementation from Quake III Arena source code with the original comment text.

Language: cpp20 months ago