剑指offer面试题28:对称的二叉树

/*
 题目:对称的二叉树
                    8
               /         \
              6           6
            /  \        /   \
           5    7      7     5
 如果一棵二叉树和自己的镜像一样,那么这棵二叉树是对称的
 */

bool isSymmetrical(BinaryTreeNode *pRoot)
{
    return isSymmetrical(pRoot,pRoot);
}
bool isSymmetrical(BinaryTreeNode *pRoot1,BinaryTreeNode *pRoot2)
{
    if(pRoot1==nullptr && pRoot2==nullptr)
        return true;
    if(pRoot1 ==nullptr || pRoot2==nullptr)
        return false;
    if(pRoot1->value!=pRoot2->value)
        return false;
    
    return BinaryTreeNode(pRoot1->left,pRoot2->right)
    && BinaryTreeNode(pRoot1->right,pRoot2->left);
}
发布了46 篇原创文章 · 获赞 0 · 访问量 428

猜你喜欢

转载自blog.csdn.net/weixin_42226134/article/details/104402340