Skip to content

Commit 02a4dcd

Browse files
committed
Added README.md file for Evaluate Boolean Binary Tree
1 parent 08fb9d9 commit 02a4dcd

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<h2><a href="https://leetcode.com/problems/evaluate-boolean-binary-tree">Evaluate Boolean Binary Tree</a></h2> <img src='https://img.shields.io/badge/Difficulty-Easy-brightgreen' alt='Difficulty: Easy' /><hr><p>You are given the <code>root</code> of a <strong>full binary tree</strong> with the following properties:</p>
2+
3+
<ul>
4+
<li><strong>Leaf nodes</strong> have either the value <code>0</code> or <code>1</code>, where <code>0</code> represents <code>False</code> and <code>1</code> represents <code>True</code>.</li>
5+
<li><strong>Non-leaf nodes</strong> have either the value <code>2</code> or <code>3</code>, where <code>2</code> represents the boolean <code>OR</code> and <code>3</code> represents the boolean <code>AND</code>.</li>
6+
</ul>
7+
8+
<p>The <strong>evaluation</strong> of a node is as follows:</p>
9+
10+
<ul>
11+
<li>If the node is a leaf node, the evaluation is the <strong>value</strong> of the node, i.e. <code>True</code> or <code>False</code>.</li>
12+
<li>Otherwise, <strong>evaluate</strong> the node&#39;s two children and <strong>apply</strong> the boolean operation of its value with the children&#39;s evaluations.</li>
13+
</ul>
14+
15+
<p>Return<em> the boolean result of <strong>evaluating</strong> the </em><code>root</code><em> node.</em></p>
16+
17+
<p>A <strong>full binary tree</strong> is a binary tree where each node has either <code>0</code> or <code>2</code> children.</p>
18+
19+
<p>A <strong>leaf node</strong> is a node that has zero children.</p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
<img alt="" src="https://assets.leetcode.com/uploads/2022/05/16/example1drawio1.png" style="width: 700px; height: 252px;" />
24+
<pre>
25+
<strong>Input:</strong> root = [2,1,3,null,null,0,1]
26+
<strong>Output:</strong> true
27+
<strong>Explanation:</strong> The above diagram illustrates the evaluation process.
28+
The AND node evaluates to False AND True = False.
29+
The OR node evaluates to True OR False = True.
30+
The root node evaluates to True, so we return true.</pre>
31+
32+
<p><strong class="example">Example 2:</strong></p>
33+
34+
<pre>
35+
<strong>Input:</strong> root = [0]
36+
<strong>Output:</strong> false
37+
<strong>Explanation:</strong> The root node is a leaf node and it evaluates to false, so we return false.
38+
</pre>
39+
40+
<p>&nbsp;</p>
41+
<p><strong>Constraints:</strong></p>
42+
43+
<ul>
44+
<li>The number of nodes in the tree is in the range <code>[1, 1000]</code>.</li>
45+
<li><code>0 &lt;= Node.val &lt;= 3</code></li>
46+
<li>Every node has either <code>0</code> or <code>2</code> children.</li>
47+
<li>Leaf nodes have a value of <code>0</code> or <code>1</code>.</li>
48+
<li>Non-leaf nodes have a value of <code>2</code> or <code>3</code>.</li>
49+
</ul>

0 commit comments

Comments
 (0)