java.lang.Object
g1101_1200.s1106_parsing_a_boolean_expression.Solution

public class Solution extends Object
1106 - Parsing A Boolean Expression.<p>Hard</p> <p>Return the result of evaluating a given boolean <code>expression</code>, represented as a string.</p> <p>An expression can either be:</p> <ul> <li><code>&quot;t&quot;</code>, evaluating to <code>True</code>;</li> <li><code>&quot;f&quot;</code>, evaluating to <code>False</code>;</li> <li><code>&quot;!(expr)&quot;</code>, evaluating to the logical NOT of the inner expression <code>expr</code>;</li> <li><code>&quot;&(expr1,expr2,...)&quot;</code>, evaluating to the logical AND of 2 or more inner expressions <code>expr1, expr2, ...</code>;</li> <li><code>&quot;|(expr1,expr2,...)&quot;</code>, evaluating to the logical OR of 2 or more inner expressions <code>expr1, expr2, ...</code></li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> expression = &ldquo;!(f)&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> expression = &ldquo;|(f,t)&rdquo;</p> <p><strong>Output:</strong> true</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> expression = &ldquo;&(t,f)&rdquo;</p> <p><strong>Output:</strong> false</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= expression.length <= 2 * 10<sup>4</sup></code></li> <li><code>expression[i]</code> consists of characters in <code>{'(', ')', '&', '|', '!', 't', 'f', ','}</code>.</li> <li><code>expression</code> is a valid expression representing a boolean, as given in the description.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • parseBoolExpr

      public boolean parseBoolExpr(String expression)