1106. Parsing A Boolean Expression
https://leetcode.com/problems/parsing-a-boolean-expression
Description
Return the result of evaluating a given boolean expression, represented as a string.
An expression can either be:
"t", evaluating toTrue;"f", evaluating toFalse;"!(expr)", evaluating to the logical NOT of the inner expressionexpr;"&(expr1,expr2,...)", evaluating to the logical AND of 2 or more inner expressionsexpr1, expr2, ...;"|(expr1,expr2,...)", evaluating to the logical OR of 2 or more inner expressionsexpr1, expr2, ...
Example 1:
**Input:** expression = "!(f)"
**Output:** trueExample 2:
**Input:** expression = "|(f,t)"
**Output:** trueExample 3:
**Input:** expression = "&(t,f)"
**Output:** falseExample 4:
**Input:** expression = "|(&(t,f,t),!(t))"
**Output:** falseConstraints:
1 <= expression.length <= 20000expression[i]consists of characters in{'(', ')', '&', '|', '!', 't', 'f', ','}.expressionis a valid expression representing a boolean, as given in the description.
ac
Last updated
Was this helpful?