Flip Equivalent Binary Trees
Problem statement
Two binary trees are flip equivalent if one can be transformed into the other by repeatedly swapping the left and right children of any node.
Return whether the two supplied trees are flip equivalent.
Function
flipEquiv(root1: TreeNode, root2: TreeNode) → booleanExamples
Example 1
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]return = trueFlips at selected nodes align both trees.
Example 2
root1 = []root2 = []return = trueTwo empty trees are equivalent.
Example 3
root1 = []root2 = [1]return = falseOnly one tree is empty.
Constraints
- Each tree has 0 to 100 nodes.
0 <= node.val <= 100.