问题描述:
判断一个二叉树是否是镜像二叉树
bool Symmetric(TreeNode* leftchild, TreeNode* rightchild)
{
if (leftchild == nullptr && rightchild==nullptr)
{
return true;
}
if ((leftchild == nullptr&& rightchild != nullptr) ||(leftchild!=nullptr&&rightchild==nullptr))
{
return false;
}
if (Symmetric(leftchild->left,rightchild->right)
&&Symmetric(leftchild->right, rightchild->left)
&&leftchild->val == rightchild->val)
{
return true;
}
else
{
return false;
}
}
//判断二叉树是否对称
bool isSymmetric(TreeNode *root)
{
if (root == nullptr)
{
return true;
}
return Symmetric(root->left, root->right);
}