Skip to content

Commit c6bb4c7

Browse files
author
William Grolleau
committed
daily
1 parent d07a84f commit c6bb4c7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

problems/problem_1190/solution_1.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
3+
4+
class Solution:
5+
def reverseParentheses(self, s: str) -> str:
6+
stack = []
7+
for c in s:
8+
if c == ")":
9+
temp = []
10+
while stack[-1] != "(":
11+
temp.append(stack.pop())
12+
stack.pop()
13+
stack.extend(temp)
14+
else:
15+
stack.append(c)
16+
return "".join(stack)
17+
18+
19+
tests = [
20+
(
21+
("(abcd)",),
22+
"dcba",
23+
),
24+
(
25+
("(u(love)i)",),
26+
"iloveu",
27+
),
28+
(
29+
("(ed(et(oc))el)",),
30+
"leetcode",
31+
),
32+
]
33+
34+
35+
@pytest.mark.timeout(2)
36+
@pytest.mark.parametrize(
37+
"inputs, expected",
38+
tests,
39+
)
40+
def test_validator(inputs, expected):
41+
output = Solution().reverseParentheses(*inputs)
42+
assert output == expected

0 commit comments

Comments
 (0)