1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-11 10:21:43 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/进行操作使字符串为空 [apply-operations-to-make-string-empty].html
2025-01-09 20:29:41 +08:00

47 lines
1.8 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>每次操作 <strong>依次</strong> 遍历 <code>'a'</code><code>'z'</code>,如果当前字符出现在 <code>s</code> 中,那么删除出现位置&nbsp;<strong>最早</strong>&nbsp;的该字符(如果存在的话)。</li>
</ul>
<p>例如,最初 <code>s = "aabcbbca"</code>。我们执行下述操作:</p>
<ul>
<li>移除下划线的字符&nbsp; <code>s = "<u><strong>a</strong></u>a<u><strong>bc</strong></u>bbca"</code>。结果字符串为 <code>s = "abbca"</code></li>
<li>移除下划线的字符&nbsp; <code>s = "<u><strong>ab</strong></u>b<u><strong>c</strong></u>a"</code>。结果字符串为 <code>s = "ba"</code></li>
<li>移除下划线的字符&nbsp; <code>s = "<u><strong>ba</strong></u>"</code>。结果字符串为 <code>s = ""</code></li>
</ul>
<p>请你返回进行 <strong>最后</strong>&nbsp;一次操作 <strong>之前</strong>&nbsp;的字符串<em>&nbsp;</em><code>s</code><em>&nbsp;</em>。在上面的例子中,答案是&nbsp;<code>"ba"</code></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>s = "aabcbbca"
<b>输出:</b>"ba"
<b>解释:</b>已经在题目描述中解释。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>s = "abcd"
<b>输出:</b>"abcd"
<b>解释:</b>我们进行以下操作:
- 删除 s = "<em><strong>abcd</strong></em>" 中加粗加斜字符,得到字符串 s = "" 。
进行最后一次操作之前的字符串为 "abcd" 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 5 * 10<sup>5</sup></code></li>
<li><code>s</code>&nbsp;只包含小写英文字母。</li>
</ul>