类似symmetric tree判断,只有满足两个数都不是NULL,而且保存值相同,L=L R=R
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
if(p == NULL && q == NULL)
return true;
else if(p != NULL && q == NULL)
return false;
else if(p == NULL && q != NULL)
return false;
else{
if(p->val == q->val)
return isSameTree(p->left,q->left)&&isSameTree(p->right, q->right);
else
return false;
}
}