Simple Recursive Java and C Solution(0ms)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n1. Simple Recursively c
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Simple Recursively check the subtrees \n# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n    public boolean flipEquiv(TreeNode root1, TreeNode root2) {\n        if (root1 == null && root2 == null)\n            return true;\n        if (root1 == null || root2 == null)\n            return false;\n        if (root1.val != root2.val) {\n            return false;\n        }\n        boolean noFlip = flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right);\n        boolean flip = flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left);\n        return noFlip || flip;\n    }\n}\n```\n```c []\nbool flipEquiv(struct TreeNode* root1, struct TreeNode* root2) {\n    if (root1 == NULL && root2 == NULL)\n        return true;\n    if (root1 == NULL || root2 == NULL)\n        return false;\n    if (root1->val != root2->val)\n        return false;\n\n    bool noFlip = flipEquiv(root1->left, root2->left) && flipEquiv(root1->right, root2->right);\n    bool flip = flipEquiv(root1->left, root2->right) && flipEquiv(root1->right, root2->left);\n\n    return noFlip || flip;\n}\n```
['C', 'Java']