104. 二叉树的最大深度

104. Maximum Depth of Binary Tree

题目描述

给定一个二叉树,找出其最大深度。

二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。

说明: 叶子节点是指没有子节点的节点。

LeetCode104. Maximum Depth of Binary Tree

示例:

给定二叉树 [3,9,20,null,null,15,7],
```
3
/ \
9 20
/ \
15 7
```
返回它的最大深度 3。

Java 实现

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

相似题目

参考资料

LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)的更多相关文章

  1. [Swift]LeetCode104. 二叉树的最大深度 | Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  2. 【Leetcode】【Easy】Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  3. 【leetcode刷题笔记】Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  4. 【easy】104. Maximum Depth of Binary Tree 求二叉树的最大深度

    求二叉树的最大深度 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

  5. leetcode 104 Maximum Depth of Binary Tree二叉树求深度

    Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...

  6. LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree

    258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...

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

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  8. LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告

    104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...

  9. 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)

    Maximum Depth of Binary Tree  Given a binary tree, find its maximum depth. The maximum depth is the ...

随机推荐

  1. layui select多选下拉显示 以及回显

    <input type="hidden" id="hiddensheshi" name="hiddensheshi" value=&q ...

  2. [代码审计]PHP_Bugs题目总结(2)

    写的有点多了,上一篇放在一起显得有点臃肿,就再起一篇吧~ 迷路的老铁点这里:[代码审计]PHP_Bugs题目总结(1) 0x14 intval函数四舍五入 <?php if($_GET[id]) ...

  3. OpenFOAM制作动画

    原视频下载地址:https://yunpan.cn/cMpfh9cCjKnZI(提取码:823b)

  4. DDD应对运营活动系统腐化实践

    前言 任何人类的设计都会腐化,软件系统也不例外 腐化之谜 随着系统的规模增长和复杂度膨胀,系统会慢慢腐化. 于是改一个很简单的下单地址,就会牵动整个交易系统十几处的改动. 如何解决这种腐化之谜呢? 参 ...

  5. Vue基础学习 --- 遍历数组

    <body> <div id="app"> <ul> <!-- 遍历数组 --> <li v-for="user i ...

  6. SELECT INTO (insert into) 和 INSERT INTO SELECT (insert into select) 两种表复制语句

    1.INSERT INTO SELECT语句   语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from T ...

  7. SQL Server 静默安装

    SQL Server 安装时,需要在各个安装窗口进行选择和设置,若需要在多台服务器安装相同的数据库,静默安装是比较省事的. 当安装 SQL Server  到最后一步,会有一个安装配置文件 Confi ...

  8. hive匹配中文

    select regexp_extract('ab中文123测试55..', '[\u4e00-\u9fa5]+', 0) 只提出成功第一段中文汉字,结果为: 中文 select regexp_rep ...

  9. 悟空CRM(基于jfinal+vue+ElementUI的前后端分离的开源CRM系统)

    https://www.jfinal.com/share/1591 官网:http://www.5kcrm.com 官网:http://www.72crm.com 论坛:http://bbs.72cr ...

  10. linux下phpmailer发送邮件出现SMTP ERROR: Failed to connect to server: (0)错误

    转自:https://www.cnblogs.com/raincowl/p/8875647.html //Create a new PHPMailer instance $mail = new PHP ...