Count Ways To Build Good Strings

by atalaykutlay

Solution to Leetcode problem Count Ways To Build Good Strings in Java.

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

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

Count Ways To Build Good Strings
Count Ways To Build Good Strings

Solution to Leetcode problem Count Ways To Build Good Strings in Java.

Language: java13 months ago