20. Valid Parentheses
注意边界问题,特别是len(stack)==0这个细节需要注意
class Solution: def isValid(self, s: str) -> bool: stack = [] lib = {} lib[')'] = '(' lib[']'] = '[' lib['}'] = '{' for i in s: if i in lib: if len(stack) == 0 or stack.pop() != lib[i]: return False else: stack.append(i) if len(stack) == 0: return True return False
做了三题