1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计构造好字符串的方案数 [count-ways-to-build-good-strings].html
2022-11-14 20:01:29 +08:00

41 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你整数&nbsp;<code>zero</code>&nbsp;<code>one</code>&nbsp;<code>low</code>&nbsp;&nbsp;<code>high</code>&nbsp;,我们从空字符串开始构造一个字符串,每一步执行下面操作中的一种:</p>
<ul>
<li>&nbsp;<code>'0'</code>&nbsp;在字符串末尾添加&nbsp;<code>zero</code>&nbsp; 次。</li>
<li>&nbsp;<code>'1'</code>&nbsp;在字符串末尾添加&nbsp;<code>one</code>&nbsp;次。</li>
</ul>
<p>以上操作可以执行任意次。</p>
<p>如果通过以上过程得到一个 <strong>长度</strong>&nbsp;&nbsp;<code>low</code>&nbsp;<code>high</code>&nbsp;之间(包含上下边界)的字符串,那么这个字符串我们称为&nbsp;<strong></strong>&nbsp;字符串。</p>
<p>请你返回满足以上要求的 <strong>不同</strong>&nbsp;好字符串数目。由于答案可能很大,请将结果对&nbsp;<code>10<sup>9</sup> + 7</code>&nbsp;<strong>取余</strong>&nbsp;后返回。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>low = 3, high = 3, zero = 1, one = 1
<b>输出:</b>8
<b>解释:</b>
一个可能的好字符串是 "011" 。
可以这样构造得到:"" -&gt; "0" -&gt; "01" -&gt; "011" 。
从 "000" 到 "111" 之间所有的二进制字符串都是好字符串。
</pre>
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>low = 2, high = 3, zero = 1, one = 2
<b>输出:</b>5
<b>解释:</b>好字符串为 "00" "11" "000" "110" 和 "011" 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= low&nbsp;&lt;= high&nbsp;&lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= zero, one &lt;= low</code></li>
</ul>