Description
A valid parentheses string is primitive if it cannot be split into two non-empty valid strings. Remove the outermost parentheses of every primitive string in the decomposition. Return the result as a string.
Examples
Input:
s = "(()())(())"Output:
"()()()"Explanation:
Remove outer parens.
Input:
s = "()()(())"Output:
"()"Explanation:
The primitive pieces are "()" and "()(())". Removing the outermost parentheses leaves an empty string from the first piece and "()" from the second piece. The exact output is "()".
Input:
s = "((()))"Output:
"(())"Explanation:
This is a single primitive decomposition "((()))". The outermost parentheses are the first '(' and last ')'. Removing them leaves the inner nested parentheses "(())".
Constraints
- •
1 ≤ s.length ≤ 10⁵