Simple 4 Lines Solution | DFS | Java
\n\n# Code\njava []\nclass Solution {\n    public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        if(root1 == null && root2 == null) return true;\n
\n\n# Code\n```java []\nclass Solution {\n    public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        if(root1 == null && root2 == null) return true;\n        if(root1 == null || root2 == null) return false;\n        if(root1.val != root2.val) return false;\n        return (flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right))\n            || (flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left));\n    }\n}\n```
['Java']