forked from onlybooks/python-algorithm-interview
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20-1.py
More file actions
16 lines (15 loc) · 442 Bytes
/
20-1.py
File metadata and controls
16 lines (15 loc) · 442 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Solution:
def isValid(self, s: str) -> bool:
stack = []
table = {
')': '(',
'}': '{',
']': '[',
}
# 스택 이용 예외 처리 및 일치 여부 판별
for char in s:
if char not in table:
stack.append(char)
elif not stack or table[char] != stack.pop():
return False
return len(stack) == 0