-
Notifications
You must be signed in to change notification settings - Fork 161
/
univalued-binary-tree.md
30 lines (23 loc) · 1.06 KB
/
univalued-binary-tree.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
<p>A binary tree is <em>univalued</em> if every node in the tree has the same value.</p>
<p>Return <code>true</code> if and only if the given tree is univalued.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/28/unival_bst_1.png" style="width: 265px; height: 172px;" />
<pre>
<strong>Input: </strong><span id="example-input-1-1">[1,1,1,1,1,null,1]</span>
<strong>Output: </strong><span id="example-output-1">true</span>
</pre>
<div>
<p><strong>Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2018/12/28/unival_bst_2.png" style="width: 198px; height: 169px;" />
<pre>
<strong>Input: </strong><span id="example-input-2-1">[2,2,2,5,2]</span>
<strong>Output: </strong><span id="example-output-2">false</span>
</pre>
</div>
<p> </p>
<p><strong>Note:</strong></p>
<ol>
<li>The number of nodes in the given tree will be in the range <code>[1, 100]</code>.</li>
<li>Each node's value will be an integer in the range <code>[0, 99]</code>.</li>
</ol>