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)/不同的子序列 II [distinct-subsequences-ii].html
2022-03-29 12:43:11 +08:00

45 lines
1.4 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>给定一个字符串 <code>s</code>,计算 <code>s</code><strong>不同非空子序列</strong> 的个数。因为结果可能很大,所以返回答案需要对<strong> </strong><strong><code>10^9 + 7</code> 取余</strong></p>
<p>字符串的 <strong>子序列</strong> 是经由原字符串删除一些(也可能不删除)字符但不改变剩余字符相对位置的一个新字符串。</p>
<ul>
<li>例如,<code>"ace"</code><code>"<em><strong>a</strong></em>b<em><strong>c</strong></em>d<em><strong>e</strong></em>"</code> 的一个子序列,但 <code>"aec"</code> 不是。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "abc"
<strong>输出:</strong>7
<strong>解释:</strong>7 个不同的子序列分别是 "a", "b", "c", "ab", "ac", "bc", 以及 "abc"。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "aba"
<strong>输出:</strong>6
<strong>解释:</strong>6 个不同的子序列分别是 "a", "b", "ab", "ba", "aa" 以及 "aba"。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "aaa"
<strong>输出:</strong>3
<strong>解释:</strong>3 个不同的子序列分别是 "a", "aa" 以及 "aaa"。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 2000</code></li>
<li><code>s</code> 仅由小写英文字母组成</li>
</ul>
<p>&nbsp;</p>