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)/操作后字符串的最短长度 [minimum-length-of-string-after-operations].html
2024-08-06 08:46:50 +08:00

50 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>s</code>&nbsp;</p>
<p>你需要对 <code>s</code>&nbsp;执行以下操作 <strong>任意</strong>&nbsp;次:</p>
<ul>
<li>选择一个下标 <code>i</code>&nbsp;,满足 <code>s[i]</code>&nbsp;左边和右边都&nbsp;<strong>至少</strong>&nbsp;有一个字符与它相同。</li>
<li>删除 <code>s[i]</code>&nbsp;<strong>左边</strong>&nbsp;离它 <strong>最近</strong>&nbsp;且相同的字符。</li>
<li>删除 <code>s[i]</code>&nbsp;<strong>右边</strong>&nbsp;离它 <strong>最近</strong>&nbsp;且相同的字符。</li>
</ul>
<p>请你返回执行完所有操作后, <code>s</code>&nbsp;<strong>最短</strong>&nbsp;长度。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "abaacbcbb"</span></p>
<p><span class="example-io"><b>输出:</b>5</span></p>
<p><strong>解释:</strong><br />
我们执行以下操作:</p>
<ul>
<li>选择下标 2 ,然后删除下标 0 和 3 处的字符,得到&nbsp;<code>s = "bacbcbb"</code>&nbsp;</li>
<li>选择下标 3 ,然后删除下标 0 和 5 处的字符,得到&nbsp;<code>s = "acbcb"</code>&nbsp;</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>s = "aa"</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong><br />
无法对字符串进行任何操作,所以返回初始字符串的长度。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 2 * 10<sup>5</sup></code></li>
<li><code>s</code>&nbsp;只包含小写英文字母。</li>
</ul>