#951
Flip Equivalent Binary Trees
pupil · 565 · lc medium +29 · verified · 69.6% accepted · 2,882 likes · top 78%
Description
Two binary trees are flip equivalent if one can be made identical to the other by swapping the left and right children of any set of nodes (zero or more times). Given root1 and root2, return true if they are flip equivalent.
Example 1:
Input: root1 = [1,2,3,4,5,6,null,null,null,7,8], root2 = [1,3,2,null,6,4,5,null,null,null,null,8,7]
Output: true
Explanation: We flipped at nodes with values 1, 3, and 5.
Example 2:
Input: root1 = [], root2 = []
Output: true
Example 3:
Input: root1 = [], root2 = [1]
Output: false
Code
1
2
3
4
5
6
7
8
9