( Leetcode 104 ) Maximum Depth of Binary Tree
2016-05-28 16:15
375 查看
题目: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.
解题思路:
这是一道很简单常用的数据结构题,简单来说通过递归方法就可以求出来。下面直接看代码吧。
Java代码:
程序运行时间 0 ms。
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.
解题思路:
这是一道很简单常用的数据结构题,简单来说通过递归方法就可以求出来。下面直接看代码吧。
Java代码:
public class Solution { public int maxDepth( TreeNode root ) { if( root == null ) { return 0; } int ldep = maxDepth( root.left ); int rdep = maxDepth( root.right ); return ldep > rdep ? ldep+1 : rdep+1; } }
程序运行时间 0 ms。
相关文章推荐
- 途牛面试经历
- websphere 启动服务
- Android中Application类用法
- 关联、组合、聚合、依赖关系比较 [转]
- 设计模式之门面模式
- How to Remove Table Partitioning in SQL Server
- Linux下如何用vi编辑和保存文件
- 时钟显示
- Hibernate基本查询(学习笔记)
- 排序算法性能和使用场景总结
- 使用FFTW的fftw_plan_dft_c2r_1d()由于未归一化结果错误的解决方案
- 消息通道looper
- Android权限适配方案(API 4+)
- 面试问题
- HELLO WORLD!
- Hadoop数据读写原理
- reflect(反射)
- getter-setter方法/点语法
- 文字转换为二进制/十六进制(Uncode编码 java实现)
- 查看CentOS系统版本是32位的还是64位的