mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 15:31:43 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,35 +1,45 @@
|
||||
<p>Return the result of evaluating a given boolean <code>expression</code>, represented as a string.</p>
|
||||
|
||||
<p>An expression can either be:</p>
|
||||
<p>A <strong>boolean expression</strong> is an expression that evaluates to either <code>true</code> or <code>false</code>. It can be in one of the following shapes:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>"t"</code>, evaluating to <code>True</code>;</li>
|
||||
<li><code>"f"</code>, evaluating to <code>False</code>;</li>
|
||||
<li><code>"!(expr)"</code>, evaluating to the logical NOT of the inner expression <code>expr</code>;</li>
|
||||
<li><code>"&(expr1,expr2,...)"</code>, evaluating to the logical AND of 2 or more inner expressions <code>expr1, expr2, ...</code>;</li>
|
||||
<li><code>"|(expr1,expr2,...)"</code>, evaluating to the logical OR of 2 or more inner expressions <code>expr1, expr2, ...</code></li>
|
||||
<li><code>'t'</code> that evaluates to <code>true</code>.</li>
|
||||
<li><code>'f'</code> that evaluates to <code>false</code>.</li>
|
||||
<li><code>'!(subExpr)'</code> that evaluates to <strong>the logical NOT</strong> of the inner expression <code>subExpr</code>.</li>
|
||||
<li><code>'&(subExpr<sub>1</sub>, subExpr<sub>2</sub>, ..., subExpr<sub>n</sub>)'</code> that evaluates to <strong>the logical AND</strong> of the inner expressions <code>subExpr<sub>1</sub>, subExpr<sub>2</sub>, ..., subExpr<sub>n</sub></code> where <code>n >= 1</code>.</li>
|
||||
<li><code>'|(subExpr<sub>1</sub>, subExpr<sub>2</sub>, ..., subExpr<sub>n</sub>)'</code> that evaluates to <strong>the logical OR</strong> of the inner expressions <code>subExpr<sub>1</sub>, subExpr<sub>2</sub>, ..., subExpr<sub>n</sub></code> where <code>n >= 1</code>.</li>
|
||||
</ul>
|
||||
|
||||
<p>Given a string <code>expression</code> that represents a <strong>boolean expression</strong>, return <em>the evaluation of that expression</em>.</p>
|
||||
|
||||
<p>It is <strong>guaranteed</strong> that the given expression is valid and follows the given rules.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "!(f)"
|
||||
<strong>Output:</strong> true
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "|(f,t)"
|
||||
<strong>Output:</strong> true
|
||||
</pre>
|
||||
|
||||
<p><strong>Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "&(t,f)"
|
||||
<strong>Input:</strong> expression = "&(|(f))"
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong>
|
||||
First, evaluate |(f) --> f. The expression is now "&(f)".
|
||||
Then, evaluate &(f) --> f. The expression is now "f".
|
||||
Finally, return false.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "|(f,f,f,t)"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong> The evaluation of (false OR false OR false OR true) is true.
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> expression = "!(&(f,t))"
|
||||
<strong>Output:</strong> true
|
||||
<strong>Explanation:</strong>
|
||||
First, evaluate &(f,t) --> (false AND true) --> false --> f. The expression is now "!(f)".
|
||||
Then, evaluate !(f) --> NOT false --> true. We return true.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
@@ -37,6 +47,5 @@
|
||||
|
||||
<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>
|
||||
<li>expression[i] is one following characters: <code>'('</code>, <code>')'</code>, <code>'&'</code>, <code>'|'</code>, <code>'!'</code>, <code>'t'</code>, <code>'f'</code>, and <code>','</code>.</li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user