Class Solution
java.lang.Object
g1001_1100.s1021_remove_outermost_parentheses.Solution
1021 - Remove Outermost Parentheses.<p>Easy</p>
<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><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “(()())(())”</p>
<p><strong>Output:</strong> “()()()”</p>
<p><strong>Explanation:</strong></p>
<p>The input string is “(()())(())”, with primitive decomposition “(()())” + “(())”.</p>
<p>After removing outer parentheses of each part, this is “()()” + “()” = “()()()”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “(()())(())(()(()))”</p>
<p><strong>Output:</strong> “()()()()(())”</p>
<p><strong>Explanation:</strong></p>
<p>The input string is “(()())(())(()(()))”, with primitive decomposition “(()())” + “(())” + “(()(()))”.</p>
<p>After removing outer parentheses of each part, this is “()()” + “()” + “()(())” = “()()()()(())”.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “()()”</p>
<p><strong>Output:</strong> ""</p>
<p><strong>Explanation:</strong></p>
<p>The input string is “()()”, with primitive decomposition “()” + “()”.</p>
<p>After removing outer parentheses of each part, this is "" + "" = "".</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>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
removeOuterParentheses
-