leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2466.cpp (446B)


      1 class Solution {
      2   public:
      3     int countGoodStrings(int low, int high, int zero, int one) {
      4         vector<int> dp(high + 1, 0);
      5         dp[0] = 1;
      6         int res = 0, mod = 1e9 + 7;
      7         for (int i = 1; i <= high; i++) {
      8             if (i >= zero) dp[i] = (dp[i] + dp[i - zero]) % mod;
      9             if (i >= one) dp[i] = (dp[i] + dp[i - one]) % mod;
     10             if (i >= low) res = (res + dp[i]) % mod;
     11         }
     12         return res;
     13     }
     14 };