1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/解析布尔表达式 [parsing-a-boolean-expression].html
2022-03-29 12:43:11 +08:00

48 lines
2.0 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个以字符串形式表述的&nbsp;<a href="https://baike.baidu.com/item/%E5%B8%83%E5%B0%94%E8%A1%A8%E8%BE%BE%E5%BC%8F/1574380?fr=aladdin" target="_blank">布尔表达式</a>boolean <code>expression</code>,返回该式的运算结果。</p>
<p>有效的表达式需遵循以下约定:</p>
<ul>
<li><code>&quot;t&quot;</code>,运算结果为 <code>True</code></li>
<li><code>&quot;f&quot;</code>,运算结果为 <code>False</code></li>
<li><code>&quot;!(expr)&quot;</code>,运算过程为对内部表达式 <code>expr</code> 进行逻辑 <strong>非的运算</strong>NOT</li>
<li><code>&quot;&amp;(expr1,expr2,...)&quot;</code>,运算过程为对 2 个或以上内部表达式 <code>expr1, expr2, ...</code> 进行逻辑 <strong>与的运算</strong>AND</li>
<li><code>&quot;|(expr1,expr2,...)&quot;</code>,运算过程为对 2 个或以上内部表达式 <code>expr1, expr2, ...</code> 进行逻辑 <strong>或的运算</strong>OR</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre><strong>输入:</strong>expression = &quot;!(f)&quot;
<strong>输出:</strong>true
</pre>
<p><strong>示例 2</strong></p>
<pre><strong>输入:</strong>expression = &quot;|(f,t)&quot;
<strong>输出:</strong>true
</pre>
<p><strong>示例 3</strong></p>
<pre><strong>输入:</strong>expression = &quot;&amp;(t,f)&quot;
<strong>输出:</strong>false
</pre>
<p><strong>示例 4</strong></p>
<pre><strong>输入:</strong>expression = &quot;|(&amp;(t,f,t),!(t))&quot;
<strong>输出:</strong>false
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= expression.length &lt;= 20000</code></li>
<li><code>expression[i]</code><code>{&#39;(&#39;, &#39;)&#39;, &#39;&amp;&#39;, &#39;|&#39;, &#39;!&#39;, &#39;t&#39;, &#39;f&#39;, &#39;,&#39;}</code> 中的字符组成。</li>
<li><code>expression</code> 是以上述形式给出的有效表达式,表示一个布尔值。</li>
</ul>