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-remove-to-make-valid-parentheses].html
2022-03-29 12:43:11 +08:00

48 lines
1.6 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>'('</code><code>')'</code> 和小写字母组成的字符串 <code>s</code></p>
<p>你需要从字符串中删除最少数目的 <code>'('</code> 或者 <code>')'</code>&nbsp;(可以删除任意位置的括号),使得剩下的「括号字符串」有效。</p>
<p>请返回任意一个合法字符串。</p>
<p>有效「括号字符串」应当符合以下&nbsp;<strong>任意一条&nbsp;</strong>要求:</p>
<ul>
<li>空字符串或只包含小写字母的字符串</li>
<li>可以被写作&nbsp;<code>AB</code><code>A</code>&nbsp;连接&nbsp;<code>B</code>)的字符串,其中&nbsp;<code>A</code>&nbsp;&nbsp;<code>B</code>&nbsp;都是有效「括号字符串」</li>
<li>可以被写作&nbsp;<code>(A)</code>&nbsp;的字符串,其中&nbsp;<code>A</code>&nbsp;是一个有效的「括号字符串」</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "lee(t(c)o)de)"
<strong>输出:</strong>"lee(t(c)o)de"
<strong>解释:</strong>"lee(t(co)de)" , "lee(t(c)ode)" 也是一个可行答案。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "a)b(c)d"
<strong>输出:</strong>"ab(c)d"
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "))(("
<strong>输出:</strong>""
<strong>解释:</strong>空字符串也是有效的
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s[i]</code>&nbsp;可能是&nbsp;<code>'('</code><code>')'</code>&nbsp;或英文小写字母</li>
</ul>