Code & Func
2018-01-26

第95天。

今天的题目比较水。

今天的题目是Same Tree:

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.

太简单了,不做太多解释了:

1
bool isSameTree(TreeNode* p, TreeNode* q) {
2
if (p == nullptr && q == nullptr) return true;
3
else if (p && q) {
4
return q->val == p->val && isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
5
} else return false;
6
}
上一条动态