Skip to content

Commit 6bdf451

Browse files
committed
Added 1 solution
1 parent 8d50ada commit 6bdf451

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
i/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* int val;
5+
* TreeNode left;
6+
* TreeNode right;
7+
* TreeNode(int x) { val = x; }
8+
* }
9+
*/
10+
class Solution {
11+
public boolean flipEquiv(TreeNode root1, TreeNode root2) {
12+
if (root1 == null && root2 == null) {
13+
return true;
14+
}
15+
if (root1 == null || root2 == null) {
16+
return false;
17+
}
18+
if (root1.val != root2.val) {
19+
return false;
20+
}
21+
return (
22+
(
23+
flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)
24+
) ||
25+
(
26+
flipEquiv(root1.left, root2.right) &&
27+
flipEquiv(root1.right, root2.left)
28+
)
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)