bumpsoo 2024-07-11 22:55:30 +09:00
parent 1479c11038
commit 4631b50ee2

View file

@ -0,0 +1,16 @@
# 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]