美文网首页
剑指 Offer 第55-1题:二叉树的深度

剑指 Offer 第55-1题:二叉树的深度

作者: 放开那个BUG | 来源:发表于2022-08-17 22:21 被阅读0次

1、前言

题目描述

2、思路

左右取最大。

3、代码

class Solution {
    public int maxDepth(TreeNode root) {
        if(root == null){
            return 0;
        }
        return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
    }
}

相关文章

网友评论

      本文标题:剑指 Offer 第55-1题:二叉树的深度

      本文链接:https://www.haomeiwen.com/subject/wtobbrtx.html