[LeetCode] 20. Valid Parentheses
Python
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
댓글남기기