Maximum Depth of Binary Tree
来源:互联网 发布:淘宝客服遇到的问题 编辑:程序博客网 时间:2024/06/10 03:03
https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
public int maxDepth(TreeNode root)
这题,真的需要解释么?有LEETCODE最高的通过率,是我第一个能够一行返回答案的题。。。
我就直接给代码吧:
public int maxDepth(TreeNode root) { return root == null ? 0 : Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; }
强烈不推荐BFS做,繁琐很多。简单来说就是统计往下递归最大的层数就是了。用bottom-top的方式返回结果。
0 0
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- Maximum Depth of Binary Tree
- XCode6 编译opencore-amr
- 调用https双向认证的webservice
- 安卓拼图游戏(一)
- VS2008 调试 WinCE7.0 的程序时无法单步执行的问题
- jqGrid 自定义 无数据提示信息
- Maximum Depth of Binary Tree
- Java版四则运算简易计算器
- iOS 学习资料整理
- groovy脚本使用map
- Linux期末复习知识点小结(四)——进程
- (hdu 2.2.4)Wolf and Rabbit(一个圆有n个数,每次数m个数,看能否遍历这个圆)
- Android学习笔记--环境搭建
- sql Update 多表
- android基础学习之android图片的三级缓存