g1101_1200.s1106_parsing_a_boolean_expression.readme.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
The newest version!
1106\. Parsing A Boolean Expression
Hard
Return the result of evaluating a given boolean `expression`, represented as a string.
An expression can either be:
* `"t"`, evaluating to `True`;
* `"f"`, evaluating to `False`;
* `"!(expr)"`, evaluating to the logical NOT of the inner expression `expr`;
* `"&(expr1,expr2,...)"`, evaluating to the logical AND of 2 or more inner expressions `expr1, expr2, ...`;
* `"|(expr1,expr2,...)"`, evaluating to the logical OR of 2 or more inner expressions `expr1, expr2, ...`
**Example 1:**
**Input:** expression = "!(f)"
**Output:** true
**Example 2:**
**Input:** expression = "|(f,t)"
**Output:** true
**Example 3:**
**Input:** expression = "&(t,f)"
**Output:** false
**Constraints:**
* 1 <= expression.length <= 2 * 104
* `expression[i]` consists of characters in `{'(', ')', '&', '|', '!', 't', 'f', ','}`.
* `expression` is a valid expression representing a boolean, as given in the description.
© 2015 - 2024 Weber Informatics LLC | Privacy Policy