Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abff2d1

Browse files
authored
Merge pull request neetcode-gh#2533 from Anukriti167/patch-10
Create 0951-flip-equivalent-binary-trees.java
2 parents cdfcdd9 + 6df3c37 commit abff2d1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public boolean flipEquiv(TreeNode root1, TreeNode root2) {
3+
if(root1 == null && root2 == null) return true;
4+
if(root1 == null || root2 == null) return false;
5+
if(root1.val != root2.val) return false;
6+
7+
if(flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)){ //if they are euqal
8+
return true;
9+
}
10+
if(flipEquiv(root1.right, root2.left) && flipEquiv(root1.left, root2.right)){ // if flipped once
11+
return true;
12+
}else{
13+
return false;
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)