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. Django基础(1)-虚拟环境的安装及配置

    virtualenv介绍 (1)做什么的?virtualenv是用于创建独立的python环境,使得多个python应用彼此独立: (2)优点: a)使不同应用开发环境独立 b)环境升级不影响其他应用 ...

  2. socket.error: [Errno 32] Broken pipe . tcp

    经过检查发现,是由于客户端请求的链接,在一次循环之后,产生的套接字关闭,没有新的客户端套接字进行请求连接,所以产生broken pipe错误

  3. 模板 - 数学 - 数论 - 扩展Euler定理

    费马(Fermat)小定理 当 \(p\) 为质数,则 \(a^{p-1}\equiv 1 \mod p\) 反之,费马小定理的逆定理不成立,这样的数叫做伪质数,最小的伪质数是341. 欧拉(Eule ...

  4. Leetcode84. 柱状图中最大的矩形(单调栈)

    84. 柱状图中最大的矩形 前置 单调栈 做法 连续区间组成的矩形,是看最短的那一块,求出每一块左边第一个小于其高度的位置,右边也同理,此块作为最短限制.需要两次单调栈 单调栈维护递增区间,每次不满足 ...

  5. Android智能手机上的音频浅析【转】

    本文转载自:https://blog.csdn.net/david_tym/article/details/80903385 手机可以说是现在人日常生活中最离不开的电子设备了.它自诞生以来,从模拟的发 ...

  6. Navicat Premium连接MySQL 1251错误和Mysql初始化root密码和允许远程访问

    Mysql初始化root密码和允许远程访问 在我们使用mysql数据库时,有时我们的程序与数据库不在同一机器上,这时我们需要远程访问数据库.缺省状态下,mysql的用户是没有远程访问的权限. 下面介绍 ...

  7. 脸型分类-Face shape classification using Inception v3

    本文链接:https://blog.csdn.net/u011961856/article/details/77984667函数解析github 代码:https://github.com/adoni ...

  8. Xamarin图表开发基础教程(1)

    Xamarin图表开发基础教程(1) 在Xamarin图表开发中,最常用的框架是OxyPlot和Microcharts.其中,OxyOPlot提供多种多样的图表类型和丰富的图表功能,可以实现各种复杂的 ...

  9. postgresql 查看用户名

    查看当前连接的用户名: foo=#select * from current_user; 或 foo=#select user; 查看所有用户名: foo=#\du 用户管理可以查看之前的博文: ht ...

  10. 让remix使用本地文件系统

    让remix使用本地文件系统   转:https://blog.csdn.net/platocnet/article/details/83376792 1. 测试发现使用npm命令安装相关环境不成功, ...