Solution
C++ []\nclass Solution {\npublic:\n    bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n        if(!root1&&!root2){\n            return 1;\n        }\n      
```C++ []\nclass Solution {\npublic:\n    bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n        if(!root1&&!root2){\n            return 1;\n        }\n        if(!root1||!root2)\n        {\n            return 0;\n        }\n        return root1->val==root2->val&&(flipEquiv(root1->right,root2->right)&&flipEquiv(root1->left,root2->left)||flipEquiv(root1->left,root2->right)&&flipEquiv(root1->right,root2->left));\n    }\n};\n```\n\n```Python3 []\nclass Solution(object):\n    def flipEquiv(self, root1, root2):\n        if root1 is root2:\n            return True\n        if not root1 or not root2 or root1.val != root2.val:\n            return False\n\n        return (self.flipEquiv(root1.left, root2.left) and\n                self.flipEquiv(root1.right, root2.right) or\n                self.flipEquiv(root1.left, root2.right) and\n                self.flipEquiv(root1.right, root2.left))\n```\n\n```Java []\nclass Solution {\n    public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        \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        \n        if (flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)) {\n            return true;\n        }\n        else if (flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left)) {\n            return true;\n        }\n        else {\n            return false;\n        }\n    }\n}\n```\n
['C++', 'Java', 'Python3']