|
| 1 | +<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> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>Append the character <code>'0'</code> <code>zero</code> times.</li> |
| 5 | + <li>Append the character <code>'1'</code> <code>one</code> times.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>This can be performed any number of times.</p> |
| 9 | + |
| 10 | +<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> |
| 11 | + |
| 12 | +<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> |
| 13 | + |
| 14 | +<p> </p> |
| 15 | +<p><strong class="example">Example 1:</strong></p> |
| 16 | + |
| 17 | +<pre> |
| 18 | +<strong>Input:</strong> low = 3, high = 3, zero = 1, one = 1 |
| 19 | +<strong>Output:</strong> 8 |
| 20 | +<strong>Explanation:</strong> |
| 21 | +One possible valid good string is "011". |
| 22 | +It can be constructed as follows: "" -> "0" -> "01" -> "011". |
| 23 | +All binary strings from "000" to "111" are good strings in this example. |
| 24 | +</pre> |
| 25 | + |
| 26 | +<p><strong class="example">Example 2:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>Input:</strong> low = 2, high = 3, zero = 1, one = 2 |
| 30 | +<strong>Output:</strong> 5 |
| 31 | +<strong>Explanation:</strong> The good strings are "00", "11", "000", "110", and "011". |
| 32 | +</pre> |
| 33 | + |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>1 <= low <= high <= 10<sup>5</sup></code></li> |
| 39 | + <li><code>1 <= zero, one <= low</code></li> |
| 40 | +</ul> |
0 commit comments