We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p
q
class Solution { public: //递归定义+分类讨论 //定义: 如果两棵树相等则左子树和左子树相同, 右子树和右子树相同, 且根的值相同 //分类讨论终止: pq其中一个为空, 直接返回false; pq均为空, 则返回true bool isSameTree(TreeNode* p, TreeNode* q) { if(!q && !p) return true; if(p && q && p->val == q->val) return isSameTree(p->left, q->left) && isSameTree(p->right, q->right); return false; } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
p
和q
,编写一个函数来检验这两棵树是否相同。如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。The text was updated successfully, but these errors were encountered: