classSolution: defisValid(self, s: str) -> bool: stack = ["sentry"] # 添加哨兵 top = 1 for i in s: if stack[top-1] == "("and i == ")": stack.pop() top -= 1 continue elif stack[top-1] == "["and i == "]": stack.pop() top -= 1 continue elif stack[top-1] == "{"and i == "}": stack.pop() top -= 1 continue stack.append(i) top += 1 print(top, stack[top-2],stack[top-1]) if top == 1: returnTrue else: returnFalse