classSolution: defparseBoolExpr(self, expression: str) -> bool: stack = [] t = f = 0
for s in expression: if s == ',': continue elif s == ')': while stack[-1] != '(': if stack.pop() == 't': t += 1 else: f += 1 stack.pop() sign = stack.pop() if sign == '!': stack.append('t'if f == 1else'f') elif sign == '|': stack.append('t'if t >= 1else'f') else: stack.append('t'if f == 0else'f') t = f = 0 else: stack.append(s) return stack[-1] == 't'