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. 金蝶kis 16.0专业版-破解01

    Kingdee.KIS.MobAppSer>MainViewModel 经过反混淆后,找到导入LIcense文件后的验证函数. 下面仅需进行逆向生成即可,为什么一定要进行生成lic文件方式进行破 ...

  2. 列出5个python标准库

    os:提供了不少与操作系统相关联的函数 sys:   通常用于命令行参数 re:   正则匹配 math: 数学运算 datetime:处理日期时间

  3. 域渗透复盘(安洵CTF线下)

    复盘线下域渗透环境Write Up 0x01 外网web到DMZ进域 外网web入口 joomla应用   192.168.0.5 反序列化打下来 GET /index.php HTTP/1.1 Ho ...

  4. legend3---21、查问题或者查插件的时候请搜索对关键词

    legend3---21.查问题或者查插件的时候请搜索对关键词 一.总结 一句话总结: 比如要查移动端的js图片裁剪插件,直接搜就“移动端的js图片裁剪插件” 千万记得问题和找资料都搜索对关键词(搜索 ...

  5. qt creator中常用快捷键

    激活欢迎模式 Ctrl + 1 激活编辑模式 Ctrl + 2 激活调试模式 Ctrl + 3 激活项目模式 Ctrl + 4 激活帮助模式 Ctrl + 5 激活输出模式 Ctrl + 6 查找当前 ...

  6. 去掉iframe周围的空白

      今天,在处理一个网页样式时,遇到了一小问题,就是调用的iframe四周出现了空白. iframe调用的代码如下: 示例: <iframe src="http://www.xxx.c ...

  7. Grafana 在添加邮件和钉钉报警之后不报警的原因是没有重启grafana 不生效重启。

    即使在grafana页面上面添加也需要重启.配置邮件配置文件更需要重启. systemctl restart grafana-server.service

  8. centos7设置rsyslog日志服务集中服务器

    centos7设置rsyslog日志服务集中服务器 环境:centos6.9_x86_64,自带的rsyslog版本是7.4.7,很多配置都不支持,于是进行升级后配置 # 安装新版本的rsyslog程 ...

  9. 【转载】 tensorflow中 tf.train.slice_input_producer 和 tf.train.batch 函数

    原文地址: https://blog.csdn.net/dcrmg/article/details/79776876 ----------------------------------------- ...

  10. GANomaly: Semi-Supervised Anomaly Detection via Adversarial Training-1-论文学习

    通过对抗训练实现半监督的异常检测 Abstract 异常检测在计算机视觉中是一个经典的问题,即从异常中确定正常,但是由于其他类(即异常类)的样本数量不足,所以数据集主要基于一个类(即正常类).虽然该问 ...