Reverse Substrings Between Parentheses
Problem statement
Given a string s containing lowercase English letters and balanced parentheses, reverse the characters inside every matched pair of parentheses, starting with the innermost pairs. Return the resulting string with all parentheses removed.
Empty input and empty parenthesis contents are valid.
Function
reverseParentheses(s: String) → StringExamples
Example 1
s = "(abcd)"return = "dcba"Reverse the only parenthesized substring.
Example 2
s = "(u(love)i)"return = "iloveu"The inner reversal produces evol; reversing uevoli produces iloveu.
Example 3
s = "a(bc)d"return = "acbd"Only the letters bc are reversed; surrounding letters keep their order.
Constraints
0 <= s.length <= 2000.scontains lowercase English letters and balanced(,)characters only.