Java | DFS | Simple | 6 lines | Clean code
Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n) on the stack\n Add your space complexity here, e.g. 
# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$ on the stack\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n  public boolean flipEquiv(TreeNode node1, TreeNode node2) {\n    if (node1 == null && node2 == null)\n      return true;\n\n    if (node1 == null || node2 == null || node1.val != node2.val)\n      return false;\n\n    return (flipEquiv(node1.left, node2.left) && flipEquiv(node1.right, node2.right)) ||\n        (flipEquiv(node1.left, node2.right) && flipEquiv(node1.right, node2.left));\n  }\n}\n```\nIf you like my solution, please upvote it!
['Tree', 'Depth-First Search', 'Binary Tree', 'Java']