This commit is contained in:
parent
1479c11038
commit
4631b50ee2
1 changed files with 16 additions and 0 deletions
|
|
@ -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]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue