java.lang.Object
g2401_2500.s2466_count_ways_to_build_good_strings.Solution

public class Solution extends Object
2466 - Count Ways To Build Good Strings.<p>Medium</p> <p>Given the integers <code>zero</code>, <code>one</code>, <code>low</code>, and <code>high</code>, we can construct a string by starting with an empty string, and then at each step perform either of the following:</p> <ul> <li>Append the character <code>'0'</code> <code>zero</code> times.</li> <li>Append the character <code>'1'</code> <code>one</code> times.</li> </ul> <p>This can be performed any number of times.</p> <p>A <strong>good</strong> string is a string constructed by the above process having a <strong>length</strong> between <code>low</code> and <code>high</code> ( <strong>inclusive</strong> ).</p> <p>Return <em>the number of <strong>different</strong> good strings that can be constructed satisfying these properties.</em> Since the answer can be large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> low = 3, high = 3, zero = 1, one = 1</p> <p><strong>Output:</strong> 8</p> <p><strong>Explanation:</strong></p> <p>One possible valid good string is &ldquo;011&rdquo;.</p> <p>It can be constructed as follows: &quot;&quot; -> &ldquo;0&rdquo; -> &ldquo;01&rdquo; -> &ldquo;011&rdquo;.</p> <p>All binary strings from &ldquo;000&rdquo; to &ldquo;111&rdquo; are good strings in this example.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> low = 2, high = 3, zero = 1, one = 2</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The good strings are &ldquo;00&rdquo;, &ldquo;11&rdquo;, &ldquo;000&rdquo;, &ldquo;110&rdquo;, and &ldquo;011&rdquo;.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= low <= high <= 10<sup>5</sup></code></li> <li><code>1 <= zero, one <= low</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countGoodStrings

      public int countGoodStrings(int low, int high, int zero, int one)