题目链接:https://leetcode.cn/problems/dui-cheng-de-er-cha-shu-lcof/?favorite=xb9nqhhg
题目:

代码:
class Solution {
public:
bool check(TreeNode *p,TreeNode *q)
{
if(p==NULL&&q==NULL)
{
return true;
}
if((p==NULL || q==NULL )||(q->val!=p->val))
{
return false;
}
return check(p->left,q->right) && check(p->right,q->left);
}
bool isSymmetric(TreeNode* root) {
if(root == NULL)
return true;
int flag = check(root,root);
return flag;
}
};
该问题考察了对二叉树结构的理解以及递归算法的应用。给定一个二叉树,我们需要检查它是否是对称的,即左子树和右子树在结构和值上都相同,或者都是空树。
520

被折叠的 条评论
为什么被折叠?



