---
description: '# Easy'
---

# 100. Same Tree

{% hint style="info" %}
Be careful with edge case
{% endhint %}

p and q are None; one of p and q is None.

{% tabs %}
{% tab title="Python" %}
```python
# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
        # edge case
        if p == None and q == None:
            return True
        
        if (p == None and q != None) or (p != None and q == None):
            return False
        
        # regular case
        if p.val != q.val:
            return False
        return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
```
{% endtab %}

{% tab title="Second Tab" %}

{% endtab %}
{% endtabs %}
