-
Notifications
You must be signed in to change notification settings - Fork 161
/
parsing-a-boolean-expression.md
49 lines (37 loc) · 1.67 KB
/
parsing-a-boolean-expression.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<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><strong>Example 4:</strong></p>
<pre>
<strong>Input:</strong> expression = "|(&(t,f,t),!(t))"
<strong>Output:</strong> false
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= expression.length <= 20000</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>