MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / flipEquiv

Method flipEquiv

FlipEquivalentBinaryTrees.java:17–35  ·  view source on GitHub ↗
(TreeNode root1, TreeNode root2)

Source from the content-addressed store, hash-verified

15 */
16class Solution {
17 public boolean flipEquiv(TreeNode root1, TreeNode root2) {
18 //base cases
19 if(root1 == null && root2==null){
20 return true;
21 }
22 if(root1 == null || root2==null){
23 return false;
24 }
25 if(root1.val!=root2.val){
26 return false;
27 }
28 //orignal
29 boolean isSame = flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right);
30 if(isSame){
31 return true;
32 }
33 //flip
34 return flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left);
35 }
36}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected