class Solution {
public:
bool isSymmetric(TreeNode *root) {
if(!root)return true;
return judge(root,root);
}
bool judge(TreeNode*r1,TreeNode*r2)
{
if(!r1&&!r2)return true;
if(!r1||!r2)return false;
if(r1->val!=r2->val)return false;
return judge(r1->left,r2->right)&&judge(r1->right,r2->left);
}
};
网友评论