mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> low = 3, high = 3, zero = 1, one = 1
 | 
						|
<strong>Output:</strong> 8
 | 
						|
<strong>Explanation:</strong> 
 | 
						|
One possible valid good string is "011". 
 | 
						|
It can be constructed as follows: "" -> "0" -> "01" -> "011". 
 | 
						|
All binary strings from "000" to "111" are good strings in this example.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> low = 2, high = 3, zero = 1, one = 2
 | 
						|
<strong>Output:</strong> 5
 | 
						|
<strong>Explanation:</strong> The good strings are "00", "11", "000", "110", and "011".
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </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>
 |