mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
43 lines
1.5 KiB
HTML
43 lines
1.5 KiB
HTML
|
<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>"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>
|
||
|
</ul>
|
||
|
|
||
|
<p> </p>
|
||
|
<p><strong>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>Output:</strong> false
|
||
|
</pre>
|
||
|
|
||
|
<p> </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>
|