-
Notifications
You must be signed in to change notification settings - Fork 160
/
flip-equivalent-binary-trees.md
29 lines (20 loc) · 1.31 KB
/
flip-equivalent-binary-trees.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
<p>For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.</p>
<p>A binary tree X is <em>flip equivalent</em> to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.</p>
<p>Write a function that determines whether two binary trees are <em>flip equivalent</em>. The trees are given by root nodes <code>root1</code> and <code>root2</code>.</p>
<p> </p>
<p><strong>Example 1:</strong></p>
<pre>
<strong>Input: </strong>root1 = <span id="example-input-1-1">[1,2,3,4,5,6,null,null,null,7,8]</span>, root2 = <span id="example-input-1-2">[1,3,2,null,6,4,5,null,null,null,null,8,7]</span>
<strong>Output: </strong><span id="example-output-1">true</span>
<strong>Explanation: </strong>We flipped at nodes with values 1, 3, and 5.
<img alt="Flipped Trees Diagram" src="https://assets.leetcode.com/uploads/2018/11/29/tree_ex.png" style="font-family: sans-serif, Arial, Verdana, "Trebuchet MS"; width: 455px; height: 200px;" />
</pre>
<p> </p>
<p><strong>Note:</strong></p>
<ol>
<li>Each tree will have at most <code>100</code> nodes.</li>
<li>Each value in each tree will be a unique integer in the range <code>[0, 99]</code>.</li>
</ol>
<div>
<p> </p>
</div>