[LeetCode 101,104][简单]对称二叉树/二叉树的最大深度

101.对称二叉树
题目链接

class Solution {
public:
    bool issame(TreeNode* a, TreeNode* b){
        if(a == NULL && b == NULL)return true;
        if(a == NULL || b == NULL)return false;
        if(a -> val != b -> val)return false;
        if(!issame(a->left, b->right))return false;
        if(!issame(a->right, b->left))return false;
        return true;
    }
    bool isSymmetric(TreeNode* root) {
        return issame(root, root);
    }
};

104.二叉树的最大深度
题目链接

class Solution {
public:
    int maxDepth(TreeNode* root) {
        if(root == NULL)return 0;
        return max(maxDepth(root->left),maxDepth(root->right))+1;
    }
};
发布了104 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/IDrandom/article/details/104151106