|
| 1 | +A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings. |
| 2 | + |
| 3 | +A valid parentheses string S is primitive if it is nonempty, and there does not exist a way to split it into S = A+B, with A and B nonempty valid parentheses strings. |
| 4 | + |
| 5 | +Given a valid parentheses string S, consider its primitive decomposition: S = P_1 + P_2 + ... + P_k, where P_i are primitive valid parentheses strings. |
| 6 | + |
| 7 | +Return S after removing the outermost parentheses of every primitive string in the primitive decomposition of S. |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +Example 1: |
| 12 | + |
| 13 | +Input: "(()())(())" |
| 14 | +Output: "()()()" |
| 15 | +Explanation: |
| 16 | +The input string is "(()())(())", with primitive decomposition "(()())" + "(())". |
| 17 | +After removing outer parentheses of each part, this is "()()" + "()" = "()()()". |
| 18 | +Example 2: |
| 19 | + |
| 20 | +Input: "(()())(())(()(()))" |
| 21 | +Output: "()()()()(())" |
| 22 | +Explanation: |
| 23 | +The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))". |
| 24 | +After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())". |
| 25 | +Example 3: |
| 26 | + |
| 27 | +Input: "()()" |
| 28 | +Output: "" |
| 29 | +Explanation: |
| 30 | +The input string is "()()", with primitive decomposition "()" + "()". |
| 31 | +After removing outer parentheses of each part, this is "" + "" = "". |
| 32 | + |
| 33 | + |
| 34 | +Note: |
| 35 | + |
| 36 | +S.length <= 10000 |
| 37 | +S[i] is "(" or ")" |
| 38 | +S is a valid parentheses string |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings. |
| 45 | + |
| 46 | +A valid parentheses string S is primitive if it is nonempty, and there does not exist a way to split it into S = A+B, with A and B nonempty valid parentheses strings. |
| 47 | + |
| 48 | +Given a valid parentheses string S, consider its primitive decomposition: S = P_1 + P_2 + ... + P_k, where P_i are primitive valid parentheses strings. |
| 49 | + |
| 50 | +Return S after removing the outermost parentheses of every primitive string in the primitive decomposition of S. |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | +Example 1: |
| 55 | + |
| 56 | +Input: "(()())(())" |
| 57 | +Output: "()()()" |
| 58 | +Explanation: |
| 59 | +The input string is "(()())(())", with primitive decomposition "(()())" + "(())". |
| 60 | +After removing outer parentheses of each part, this is "()()" + "()" = "()()()". |
| 61 | +Example 2: |
| 62 | + |
| 63 | +Input: "(()())(())(()(()))" |
| 64 | +Output: "()()()()(())" |
| 65 | +Explanation: |
| 66 | +The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))". |
| 67 | +After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())". |
| 68 | +Example 3: |
| 69 | + |
| 70 | +Input: "()()" |
| 71 | +Output: "" |
| 72 | +Explanation: |
| 73 | +The input string is "()()", with primitive decomposition "()" + "()". |
| 74 | +After removing outer parentheses of each part, this is "" + "" = "". |
| 75 | + |
| 76 | + |
| 77 | +Note: |
| 78 | + |
| 79 | +S.length <= 10000 |
| 80 | +S[i] is "(" or ")" |
| 81 | +S is a valid parentheses string |
0 commit comments