---
# System prepended metadata

title: '**Leetcode筆記(Flip Equivalent Binary Trees)**'
tags: [medium, binary tree, microsoft, leetcode]

---

# **Leetcode筆記(Flip Equivalent Binary Trees)**


:::info
:information_source: 題目 : Flip Equivalent Binary Trees, 類型 : binary tree , 等級 : medium
日期 : 2023/11/29
:::


### 嘗試
```python

```

---
### **優化**

```python
class Solution:
    def flipEquiv(self, root1: Optional[TreeNode], root2: Optional[TreeNode]) -> bool:
        
        def isValid(node1, node2):
            if not node1 and not node2:
                return True
            if not node1 or not node2:
                return False
            if node1.val != node2.val:
                return False
            
            return (isValid(node1.right, node2.right) and isValid(node1.left, node2.left)) or (isValid(node1.right, node2.left) and isValid(node1.left, node2.right))
        
        return isValid(root1, root2)
```
---



**思路**


**講解連結**

Provided by. 
