Skip to content

Commit f22ae34

Browse files
committed
feat: 6 weeks
1 parent fbe9a3f commit f22ae34

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

valid-parentheses/chordpli.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def isValid(self, s: str) -> bool:
3+
if not s or len(s) % 2 == 1:
4+
return False
5+
6+
open_symbols = ['(', '[', '{']
7+
open_box = []
8+
9+
for char in list(s):
10+
if char in open_symbols:
11+
open_box.append(char)
12+
elif char not in open_symbols:
13+
if not open_box:
14+
return False
15+
open_symbol = open_box.pop()
16+
if open_symbol == '(' and char == ')':
17+
continue
18+
elif open_symbol == '[' and char == ']':
19+
continue
20+
elif open_symbol == '{' and char == '}':
21+
continue
22+
else:
23+
return False
24+
25+
return len(open_box) == 0

0 commit comments

Comments
 (0)