mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
52 lines
2.6 KiB
HTML
52 lines
2.6 KiB
HTML
<p>A valid parentheses string is either empty <code>""</code>, <code>"(" + A + ")"</code>, or <code>A + B</code>, where <code>A</code> and <code>B</code> are valid parentheses strings, and <code>+</code> represents string concatenation.</p>
|
|
|
|
<ul>
|
|
<li>For example, <code>""</code>, <code>"()"</code>, <code>"(())()"</code>, and <code>"(()(()))"</code> are all valid parentheses strings.</li>
|
|
</ul>
|
|
|
|
<p>A valid parentheses string <code>s</code> is primitive if it is nonempty, and there does not exist a way to split it into <code>s = A + B</code>, with <code>A</code> and <code>B</code> nonempty valid parentheses strings.</p>
|
|
|
|
<p>Given a valid parentheses string <code>s</code>, consider its primitive decomposition: <code>s = P<sub>1</sub> + P<sub>2</sub> + ... + P<sub>k</sub></code>, where <code>P<sub>i</sub></code> are primitive valid parentheses strings.</p>
|
|
|
|
<p>Return <code>s</code> <em>after removing the outermost parentheses of every primitive string in the primitive decomposition of </em><code>s</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong>Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "(()())(())"
|
|
<strong>Output:</strong> "()()()"
|
|
<strong>Explanation:</strong>
|
|
The input string is "(()())(())", with primitive decomposition "(()())" + "(())".
|
|
After removing outer parentheses of each part, this is "()()" + "()" = "()()()".
|
|
</pre>
|
|
|
|
<p><strong>Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "(()())(())(()(()))"
|
|
<strong>Output:</strong> "()()()()(())"
|
|
<strong>Explanation:</strong>
|
|
The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))".
|
|
After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())".
|
|
</pre>
|
|
|
|
<p><strong>Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> s = "()()"
|
|
<strong>Output:</strong> ""
|
|
<strong>Explanation:</strong>
|
|
The input string is "()()", with primitive decomposition "()" + "()".
|
|
After removing outer parentheses of each part, this is "" + "" = "".
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= s.length <= 10<sup>5</sup></code></li>
|
|
<li><code>s[i]</code> is either <code>'('</code> or <code>')'</code>.</li>
|
|
<li><code>s</code> is a valid parentheses string.</li>
|
|
</ul>
|