# 100. Same Tree

{% embed url="<https://leetcode.com/problems/same-tree/>" %}

递归验证 val 相等，处理下 leave node 的情况。

```python
class Solution:
    def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
        if not p and not q: 
            return True
        if p and q and p.val != q.val: 
            return False
        if p and q and p.val == q.val: 
            return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
```
