We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fbe9a3f commit f22ae34Copy full SHA for f22ae34
valid-parentheses/chordpli.py
@@ -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
15
+ open_symbol = open_box.pop()
16
+ if open_symbol == '(' and char == ')':
17
+ continue
18
+ elif open_symbol == '[' and char == ']':
19
20
+ elif open_symbol == '{' and char == '}':
21
22
+ else:
23
24
25
+ return len(open_box) == 0
0 commit comments