IT常识
技术 Python PHP JavaScript IOS Android Java 数据库 资源 公众号 代码片段 github
  • IT常识
  • 技术

Lintcode 97.二叉树的最大深度

Posted 2020-08-26

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lintcode 97.二叉树的最大深度相关的知识,希望对你有一定的参考价值。

---------------------------------

 

AC代码:

/**
 * Definition of TreeNode:
 * public class TreeNode {
 *     public int val;
 *     public TreeNode left, right;
 *     public TreeNode(int val) {
 *         this.val = val;
 *         this.left = this.right = null;
 *     }
 * }
 */
public class Solution {
    /**
     * @param root: The root of binary tree.
     * @return: An integer.
     */
    public int maxDepth(TreeNode root) {
        if(root==null) return 0;
        return Math.max(maxDepth(root.left),maxDepth(root.right))+1;
    }
}

 

题目来源: http://www.lintcode.com/zh-cn/problem/maximum-depth-of-binary-tree/

 

以上是关于Lintcode 97.二叉树的最大深度的主要内容,如果未能解决你的问题,请参考以下文章

97.二叉树的最大深度

[LintCode] Maximum Depth of Binary Tree 二叉树的最大深度

LintCode 二叉树的最小深度

LintCode 155. 二叉树的最小深度

代码随想录算法训练营第16天 | ● 104.二叉树的最大深度 559.n叉树的最大深度 ● 111.二叉树的最小深度 ● 222.完全二叉树的节点个数

lintcode:二叉树的所有路径

(c)2006-2024 SYSTEM All Rights Reserved IT常识