-
Notifications
You must be signed in to change notification settings - Fork 0
/
20.py
22 lines (22 loc) · 839 Bytes
/
20.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Solution:
def isValid(self, s_string: str) -> bool:
char_stack = []
char_set = set(['(',')','{','}','[',']'])
for s in s_string:
if s in char_set:
if s == '(':
char_stack.append(s)
elif s == ')':
if not char_stack or char_stack.pop() != '(':
return False
elif s == '{':
char_stack.append(s)
elif s == '}':
if not char_stack or char_stack.pop() != '{':
return False
elif s == '[':
char_stack.append(s)
elif s == ']':
if not char_stack or char_stack.pop() != '[':
return False
return not char_stack