# Leetcode 100. Same Tree (C語言)
- 題目
Given two binary trees, write a function to check if they are the same or not.
Two binary trees are considered the same if they are structurally identical and the nodes have the same value.
- 範例
```
Input:
1 1
/ \ / \
2 3 2 3
[1,2,3], [1,2,3]
Output: true
```
```c=
bool isSameTree(struct TreeNode* p, struct TreeNode* q){
if((p&&!q)||(!p&&q))return false;
if(!p&&!q)return true;
return((p->val==q->val)&&isSameTree(p->left,q->left)&&isSameTree(p->right,q->right));
}
```
思路:每個點的比較有三種可能
1. 其中一點為空,則樹必然不同 return false。
2. 兩點皆空,return true。
3. 兩點皆不空,看值是否相同,且接著檢查左子樹跟右子樹。