LeetCode全集请参考:LeetCode Github 大全

题目

104. Maximum Depth of Binary Tree

Given the root of a binary tree, return its maximum depth.

A binary tree’s maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

Example 1:

Input: root = [3,9,20,null,null,15,7]
Output: 3

Example 2:

Input: root = [1,null,2]
Output: 2

Example 3:

Input: root = []
Output: 0

Example 4:

Input: root = [0]
Output: 1

Constraints:

The number of nodes in the tree is in the range [0, 104].
-100 <= Node.val <= 100

深度优先算法

/*** Definition for a binary tree node.* public class TreeNode {*     int val;*     TreeNode left;*     TreeNode right;*     TreeNode() {}*     TreeNode(int val) { this.val = val; }*     TreeNode(int val, TreeNode left, TreeNode right) {*         this.val = val;*         this.left = left;*         this.right = right;*     }* }*/
class Solution {public int maxDepth(TreeNode root) {// check edgeif (root == null) {return 0;}return 1 + Math.max(maxDepth(root.left), maxDepth(root.right));}
}

算法:求树的最大深度104. Maximum Depth of Binary Tree相关推荐

  1. 【LeetCode 剑指offer刷题】树题4:104 Maximum Depth of Binary Tree

    [LeetCode & 剑指offer 刷题笔记]目录(持续更新中...) 104. Maximum Depth of Binary Tree Given a binary tree, fin ...

  2. LC 104. Maximum Depth of Binary Tree

    1.题意 104. Maximum Depth of Binary Tree Easy 98540 Given a binary tree, find its maximum depth. The m ...

  3. 【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 ...

  4. C#LeetCode刷题之#104-二叉树的最大深度​​​​​​​(Maximum Depth of Binary Tree)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4072 访问. 给定一个二叉树,找出其最大深度. 二叉树的深度为根 ...

  5. leetcode 104. Maximum Depth of Binary Tree

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

  6. leetcode python3 简单题104. Maximum Depth of Binary Tree

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百零四题 (1)题目 英文: Given a binary tree, find ...

  7. 104. Maximum Depth of Binary Tree (Easy)

    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

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

  9. Leet Code OJ 104. Maximum Depth of Binary Tree [Difficulty: Easy]

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

  10. 【leetcode】104. Maximum Depth of Binary Tree

    1. 题目 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...

最新文章

  1. 翡润年华-毛货展示003
  2. js中常用的算法排序
  3. 机器人焊枪动作与编程实验_机器人编程实验报告.pdf
  4. 从零开始学python项目_从零开始可以这样学python
  5. 1-4flink概述
  6. POJ NOI MATH-7652 乘积最大的拆分
  7. git理解HEAD,master
  8. 自适应漫画手机APP应用下载页源码
  9. [渝粤教育] 西南科技大学 交通管理与控制 在线考试复习资料2021版
  10. linux服务器怎么拷贝文件,linux 服务器之间拷贝文件
  11. xshell上传文件插件lrzsz
  12. linux ubi 分区,ubi卷重分区及卷创建流程解析
  13. Hadoop3+Hive3安装记录(虚拟机搭建分布式环境,报错解决)
  14. idea创建的maven web工程如何修改web版本
  15. ASCII、Unicode、UTF-8 和 Base64 等编码
  16. vivo8.0系统机器最完美激活xposed框架的方法
  17. (logN)²是O(N)的
  18. 10 款免费 PDF 阅读器软件工具分享
  19. 2023第八届少儿模特明星盛典 小超模矫沐含 担任全球赛代言人
  20. 75道经典AI面试题,我就想把你们安排的明明白白的!(含答案)

热门文章

  1. 程序员的离职小技巧之如何写出让接班同事无法维护的超级代码!建议收藏
  2. python课题_python课题报告
  3. 人体识别_你知道人脸识别,但你知道人体识别吗?ReID技术了解一下!
  4. 增加小球python,python实现弹跳小球
  5. C# 从MongoDB导入数据到mysql
  6. ASP.NET的Session会导致的性能问题
  7. nodejs导出excel
  8. 12.python之pymsql模块
  9. OSI参考模型与排错
  10. Windows 7 SP1开发完毕 已进入测试阶段