Problem
Solution
class Solution:
def isValid(self, s: str) -> bool:
stack = []
map = {
')': '(',
'}': '{',
']': '['
}
if len(s) == 0:
return True
for str in s:
if str in map.values(): # 左括号
stack.append(str)
elif str in map.keys(): # 右括号
if len(stack) == 0:
return False
else:
if stack[-1] == map[str]:
stack.pop()
else:
return False
return len(stack)==0