2
public boolean flipEquiv(TreeNode root1, TreeNode root2) {3
return helper(root1, root2);6
private boolean helper(TreeNode x, TreeNode y) {7
if (x == null && y == null) return true;8
if (x == null || y == null || x.val != y.val) return false;10
helper(x.left, y.left) && helper(x.right, y.right); // check if 2 subtrees are similar12
helper(x.left, y.right)15
y.left); // check if the 2 subtrees can be similar after swapping the left & right16
// subtrees with each other18
return similarity || swap; // if either true, means we can flip to match both trees