16 lines
520 B
Python
16 lines
520 B
Python
# https://leetcode.com/problems/reverse-substrings-between-each-pair-of-parentheses
|
|
from typing import List
|
|
|
|
class Solution:
|
|
def reverseParentheses(self, s: str) -> str:
|
|
stack: List[str] = ['']
|
|
for c in s:
|
|
match c:
|
|
case '(':
|
|
stack.append('')
|
|
case ')':
|
|
top = stack.pop()[::-1]
|
|
stack[len(stack)-1] += top
|
|
case _:
|
|
stack[len(stack)-1] += c
|
|
return stack[0]
|