mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
53 lines
2.5 KiB
HTML
53 lines
2.5 KiB
HTML
<p><strong>特殊序列</strong> 是由 <strong>正整数</strong> 个 <code>0</code> ,紧接着 <strong>正整数</strong> 个 <code>1</code> ,最后 <strong>正整数</strong> 个 <code>2</code> 组成的序列。</p>
|
||
|
||
<ul>
|
||
<li>比方说,<code>[0,1,2]</code> 和 <code>[0,0,1,1,1,2]</code> 是特殊序列。</li>
|
||
<li>相反,<code>[2,1,0]</code> ,<code>[1]</code> 和 <code>[0,1,2,0]</code> 就不是特殊序列。</li>
|
||
</ul>
|
||
|
||
<p>给你一个数组 <code>nums</code> (<strong>仅</strong> 包含整数 <code>0</code>,<code>1</code> 和 <code>2</code>),请你返回 <b>不同特殊子序列的数目</b> 。由于答案可能很大,请你将它对 <code>10<sup>9</sup> + 7</code> <strong>取余</strong> 后返回。</p>
|
||
|
||
<p>一个数组的 <strong>子序列</strong> 是从原数组中删除零个或者若干个元素后,剩下元素不改变顺序得到的序列。如果两个子序列的 <strong>下标集合</strong> 不同,那么这两个子序列是 <strong>不同的</strong> 。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>示例 1:</strong></p>
|
||
|
||
<pre>
|
||
<b>输入:</b>nums = [0,1,2,2]
|
||
<b>输出:</b>3
|
||
<b>解释:</b>特殊子序列为 [<strong>0</strong>,<strong>1</strong>,<strong>2</strong>,2],[<strong>0</strong>,<strong>1</strong>,2,<strong>2</strong>] 和 [<strong>0</strong>,<strong>1</strong>,<strong>2</strong>,<strong>2</strong>] 。
|
||
</pre>
|
||
|
||
<p><strong>示例 2:</strong></p>
|
||
|
||
<pre>
|
||
<b>输入:</b>nums = [2,2,0,0]
|
||
<b>输出:</b>0
|
||
<b>解释:</b>数组 [2,2,0,0] 中没有特殊子序列。
|
||
</pre>
|
||
|
||
<p><strong>示例 3:</strong></p>
|
||
|
||
<pre>
|
||
<b>输入:</b>nums = [0,1,2,0,1,2]
|
||
<b>输出:</b>7
|
||
<b>解释:</b>特殊子序列包括:
|
||
- [<strong>0</strong>,<strong>1</strong>,<strong>2</strong>,0,1,2]
|
||
- [<strong>0</strong>,<strong>1</strong>,2,0,1,<strong>2</strong>]
|
||
- [<strong>0</strong>,<strong>1</strong>,<strong>2</strong>,0,1,<strong>2</strong>]
|
||
- [<strong>0</strong>,<strong>1</strong>,2,0,<strong>1</strong>,<strong>2</strong>]
|
||
- [<strong>0</strong>,1,2,<strong>0</strong>,<strong>1</strong>,<strong>2</strong>]
|
||
- [<strong>0</strong>,1,2,0,<strong>1</strong>,<strong>2</strong>]
|
||
- [0,1,2,<strong>0</strong>,<strong>1</strong>,<strong>2</strong>]
|
||
</pre>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
||
<li><code>0 <= nums[i] <= 2</code></li>
|
||
</ul>
|