1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
if(p == NULL || q == NULL)
return p == q;
else
return p->val == q->val && isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
}