---
# System prepended metadata

title: 100. Same Tree
tags: [LeetCode]

---

###### tags: `LeetCode`
# 100. Same Tree

## 題目

判斷兩棵樹是不是一樣的。

## 程式碼

```cpp=
class Solution {
public:
    bool isSameTree(TreeNode* p, TreeNode* q) 
    {
        if(p == NULL && q == NULL)
            return true;
        if(!p || !q)
            return false;
        return p->val == q->val && isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
    }
};
```