Package g1601_1700.s1609_even_odd_tree
Class Solution
java.lang.Object
g1601_1700.s1609_even_odd_tree.Solution
1609 - Even Odd Tree.<p>Medium</p>
<p>A binary tree is named <strong>Even-Odd</strong> if it meets the following conditions:</p>
<ul>
<li>The root of the binary tree is at level index <code>0</code>, its children are at level index <code>1</code>, their children are at level index <code>2</code>, etc.</li>
<li>For every <strong>even-indexed</strong> level, all nodes at the level have <strong>odd</strong> integer values in <strong>strictly increasing</strong> order (from left to right).</li>
<li>For every <strong>odd-indexed</strong> level, all nodes at the level have <strong>even</strong> integer values in <strong>strictly decreasing</strong> order (from left to right).</li>
</ul>
<p>Given the <code>root</code> of a binary tree, <em>return</em> <code>true</code> <em>if the binary tree is <strong>Even-Odd</strong> , otherwise return</em> <code>false</code><em>.</em></p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/15/sample_1_1966.png" alt="" /></p>
<p><strong>Input:</strong> root = [1,10,4,3,null,7,9,12,8,6,null,null,2]</p>
<p><strong>Output:</strong> true</p>
<p><strong>Explanation:</strong> The node values on each level are:</p>
<p>Level 0: [1]</p>
<p>Level 1: [10,4]</p>
<p>Level 2: [3,7,9]</p>
<p>Level 3: [12,8,6,2]</p>
<p>Since levels 0 and 2 are all odd and increasing and levels 1 and 3 are all even and decreasing, the tree is Even-Odd.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/15/sample_2_1966.png" alt="" /></p>
<p><strong>Input:</strong> root = [5,4,2,3,3,7]</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> The node values on each level are:</p>
<p>Level 0: [5]</p>
<p>Level 1: [4,2]</p>
<p>Level 2: [3,3,7]</p>
<p>Node values in level 2 must be in strictly increasing order, so the tree is not Even-Odd.</p>
<p><strong>Example 3:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/22/sample_1_333_1966.png" alt="" /></p>
<p><strong>Input:</strong> root = [5,9,1,3,5,7]</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong> Node values in the level 1 should be even integers.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the tree is in the range <code>[1, 10<sup>5</sup>]</code>.</li>
<li><code>1 <= Node.val <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isEvenOddTree
-