1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/长度为 3 的不同回文子序列 [unique-length-3-palindromic-subsequences].html
2022-03-29 12:43:11 +08:00

54 lines
2.0 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>长度为 3 </strong><strong>不同回文子序列</strong> 的个数。</p>
<p>即便存在多种方法来构建相同的子序列,但相同的子序列只计数一次。</p>
<p><strong>回文</strong> 是正着读和反着读一样的字符串。</p>
<p><strong>子序列</strong> 是由原字符串删除其中部分字符(也可以不删除)且不改变剩余字符之间相对顺序形成的一个新字符串。</p>
<ul>
<li>例如,<code>"ace"</code><code>"<strong><em>a</em></strong>b<strong><em>c</em></strong>d<strong><em>e</em></strong>"</code> 的一个子序列。</li>
</ul>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "aabca"
<strong>输出:</strong>3
<strong>解释:</strong>长度为 3 的 3 个回文子序列分别是:
- "aba" ("<strong><em>a</em></strong>a<strong><em>b</em></strong>c<strong><em>a</em></strong>" 的子序列)
- "aaa" ("<strong><em>aa</em></strong>bc<strong><em>a</em></strong>" 的子序列)
- "aca" ("<strong><em>a</em></strong>ab<strong><em>ca</em></strong>" 的子序列)
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "adc"
<strong>输出:</strong>0
<strong>解释:</strong>"adc" 不存在长度为 3 的回文子序列。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "bbcbaba"
<strong>输出:</strong>4
<strong>解释:</strong>长度为 3 的 4 个回文子序列分别是:
- "bbb" ("<strong><em>bb</em></strong>c<strong><em>b</em></strong>aba" 的子序列)
- "bcb" ("<strong><em>b</em></strong>b<strong><em>cb</em></strong>aba" 的子序列)
- "bab" ("<strong><em>b</em></strong>bcb<strong><em>ab</em></strong>a" 的子序列)
- "aba" ("bbcb<strong><em>aba</em></strong>" 的子序列)
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 <= s.length <= 10<sup>5</sup></code></li>
<li><code>s</code> 仅由小写英文字母组成</li>
</ul>