104 二叉树的最大深度

https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/description/

class Solution {
    public int maxDepth(TreeNode root) {
        if(root == null)
            return 0;

        int leftres = maxDepth(root.left) + 1;
        int rightres = maxDepth(root.right) + 1;
        return Math.max(leftres,rightres);
    }
}

猜你喜欢

转载自blog.csdn.net/xuchonghao/article/details/80573476
今日推荐