2
2
3
3
import com .fishercoder .common .classes .TreeNode ;
4
4
5
- /**
6
- * 951. Flip Equivalent Binary Trees
7
- *
8
- * For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left and right child subtrees.
9
- *
10
- * A binary tree X is flip equivalent to a binary tree Y if and only if we can make X equal to Y after some number of flip operations.
11
- *
12
- * Write a function that determines whether two binary trees are flip equivalent. The trees are given by root nodes root1 and root2.
13
- *
14
- * Note:
15
- * * Each tree will have at most 100 nodes.
16
- * * Each value in each tree will be a unique integer in the range [0, 99].
17
- */
18
-
19
5
public class _951 {
20
6
public static class Solution1 {
21
7
public boolean flipEquiv (TreeNode root1 ,TreeNode root2 ) {
@@ -31,8 +17,8 @@ public boolean flipEquiv(TreeNode root1, TreeNode root2) {
31
17
}
32
18
33
19
return (
34
- (flipEquiv (root1 .left ,root2 .left ) &&flipEquiv (root1 .right ,root2 .right ))
35
- || (flipEquiv (root1 .left ,root2 .right ) &&flipEquiv (root1 .right ,root2 .left ))
20
+ (flipEquiv (root1 .left ,root2 .left ) &&flipEquiv (root1 .right ,root2 .right ))
21
+ || (flipEquiv (root1 .left ,root2 .right ) &&flipEquiv (root1 .right ,root2 .left ))
36
22
);
37
23
}
38
24
}