leetcode 判断两棵树是否一致Same Tree

思路:

递归判断即可:

 bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
    if(p==NULL&&q==NULL)return 1;
	if(p==NULL||q==NULL)return 0;
	if(p->val!=q->val)return 0;
	else {
		return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);}

}


你可能感兴趣的:(leetcode 判断两棵树是否一致Same Tree)