Check Flip Equivalence of Binary Trees Using Recursion | Java | C++ | Video Solution
Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/8G_jqkNVEAQ\n# Code\njava []\nclass Solution {\n    public boolean f
# Intuition, approach, and complexity discussed in video solution in detail\nhttps://youtu.be/8G_jqkNVEAQ\n# Code\n```java []\nclass Solution {\n    public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        if(root2 == null && root1 == null)return true;\n        if(root1 != null && root2 == null)return false;\n        if(root2 != null && root1 == null)return false;\n        if(root1.val != root2.val)return false;\n        boolean sameComp  = flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right);\n        boolean revComp = flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left);\n        return sameComp || revComp;\n    }\n}\n```\n```cpp []\nclass Solution {\npublic:\n    bool flipEquiv(TreeNode* root1, TreeNode* root2) {\n        if(root2 == NULL && root1 == NULL)return true;\n        if(root1 != NULL && root2 == NULL)return false;\n        if(root2 != NULL && root1 == NULL)return false;\n        if(root1->val != root2->val)return false;\n        bool sameComp  = flipEquiv(root1->left, root2->left) && flipEquiv(root1->right, root2->right);\n        bool revComp = flipEquiv(root1->left, root2->right) && flipEquiv(root1->right, root2->left);\n        return sameComp || revComp;\n    }\n};\n```
['Tree', 'Depth-First Search', 'Binary Tree', 'C++', 'Java']