Skip to content

Commit 8c8abc9

Browse files
JanaDrazkovaZelenyMartin
authored andcommitted
33 Valid parentheses
1 parent a51fb0e commit 8c8abc9

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
# task_33_valid_parentheses.py
22

3+
def erase_brackets(s, par):
4+
if par not in s:
5+
return s
6+
pos = s.index(par)
7+
s = s[:pos] + s[pos + 2:]
8+
return s
9+
10+
311
def valid_parentheses(s: str) -> bool:
412
"""
513
Zjistí, zda má řetězec validní závorky.
614
"""
7-
15+
while '()' in s or '[]' in s or '{}' in s:
16+
for par in '()', '[]', '{}':
17+
s = erase_brackets(s, par)
18+
return s == ''

0 commit comments

Comments
 (0)