题解 | #对称的二叉树#

对称的二叉树

https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb

bool isSymmetricalTree(struct TreeNode* pRoot, struct TreeNode* pRoot2) {
    if (pRoot == NULL && pRoot2 == NULL)
        return true;

    if (pRoot == NULL || pRoot2 == NULL)
        return false;

    if (pRoot->val == pRoot2->val) {
        if (isSymmetricalTree(pRoot->left, pRoot2->right) &&
                isSymmetricalTree(pRoot2->left, pRoot->right))
            return true;
    }

    return false;
}
bool isSymmetrical(struct TreeNode* pRoot ) {
    // write code here
    if (pRoot == NULL)
        return true;

    return isSymmetricalTree(pRoot->left, pRoot->right);
}

全部评论

相关推荐

10-03 17:08
已编辑
西安电子科技大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务