# 2466. Count Ways To Build Good Strings ###### tags: `Leetcode` `Medium` `Dynamic Programming` Link: https://leetcode.com/problems/count-ways-to-build-good-strings/description/ ## 思路 和[0518. Coin Change 2](https://hackmd.io/azimrNJRRUK0CBaC2d0Ivg)差不多 ```dp[i] = dp[i-zero]+dp[i-one]``` ## Code ```java= class Solution { public int countGoodStrings(int low, int high, int zero, int one) { long[] dp = new long[high+1]; dp[0] = 1; long ans = 0; int mod = 1000000007; for(int i=1; i<=high; i++){ if(i-zero>=0) dp[i] = (dp[i]+dp[i-zero])%mod; if(i-one>=0) dp[i] = (dp[i]+dp[i-one])%mod; if(i>=low && i<=high) ans = (ans+dp[i])%mod; } return (int)ans; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up