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)/删除最外层的括号 [remove-outermost-parentheses].html
2022-03-29 12:43:11 +08:00

53 lines
2.1 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>""</code><code>"(" + A + ")"</code> 或 <code>A + B</code> ,其中 <code>A</code> 和 <code>B</code> 都是有效的括号字符串,<code>+</code> 代表字符串的连接。</p>
<ul>
<li>例如,<code>""</code><code>"()"</code><code>"(())()"</code> 和 <code>"(()(()))"</code> 都是有效的括号字符串。</li>
</ul>
<p>如果有效字符串 <code>s</code> 非空,且不存在将其拆分为 <code>s = A + B</code> 的方法,我们称其为<strong>原语primitive</strong>,其中 <code>A</code> 和 <code>B</code> 都是非空有效括号字符串。</p>
<p>给出一个非空有效字符串 <code>s</code>,考虑将其进行原语化分解,使得:<code>s = P_1 + P_2 + ... + P_k</code>,其中 <code>P_i</code> 是有效括号字符串原语。</p>
<p><code>s</code> 进行原语化分解,删除分解中每个原语字符串的最外层括号,返回 <code>s</code></p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s = "(()())(())"
<strong>输出:</strong>"()()()"
<strong>解释:
</strong>输入字符串为 "(()())(())",原语化分解得到 "(()())" + "(())"
删除每个部分中的最外层括号后得到 "()()" + "()" = "()()()"。</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s = "(()())(())(()(()))"
<strong>输出:</strong>"()()()()(())"
<strong>解释:</strong>
输入字符串为 "(()())(())(()(()))",原语化分解得到 "(()())" + "(())" + "(()(()))"
删除每个部分中的最外层括号后得到 "()()" + "()" + "()(())" = "()()()()(())"。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s = "()()"
<strong>输出:</strong>""
<strong>解释:</strong>
输入字符串为 "()()",原语化分解得到 "()" + "()"
删除每个部分中的最外层括号后得到 "" + "" = ""。
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
<li><code>s[i]</code><code>'('</code><code>')'</code></li>
<li><code>s</code> 是一个有效括号字符串</li>
</ul>