Python3 代码
class Solution:
def isValid(self, s: str) -> bool:
stack = []
for c in s:
if c == '[' or c == '{' or c == '(':
stack.append(c)
else:
if len(stack) > 0 and abs(ord(stack[-1]) - ord(c)) <=2: stack.pop()
else:
return False
if len(stack) == 0:
return True
else:
return False