Count Ways To Build Good Strings

by atalaykutlay

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

Count Ways To Build Good Strings
1class Solution:
2    def countGoodStrings(self, low: int, high: int, zero: int, one: int) -> int:
3        dp = [0] * (high+1)
4        dp[0] = 1
5        ans = 0
6        for i in range(1, high+1):
7            dp[i] = ((dp[i-zero] if i-zero>=0 else 0) + (dp[i-one] if i-one>=0 else 0)) % 1000000007
8            if i >= low:
9                ans = (ans + dp[i]) % 1000000007
10        return ans

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 Number of Texts
Count Number of Texts

Solution to "Count Number of Texts" question on Leetcode.

Language: python12 months ago
Quicksort in Python
Quicksort in Python

An easy quicksort implementation in Python.

Language: python13 months ago
Second Minimum Node In a Binary Tree
Second Minimum Node In a Binary Tree

Solution to "Second Minimum Node In a Binary Tree" on Leetcode.

Language: python11 months ago