Maximum Depth of Binary Tree
2016-06-17 14:35
253 查看
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.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
/** * Definition for a binary tree node. * public 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; int leftdepth = maxDepth(root.left); int rightdepth = maxDepth(root.right); return Math.max(leftdepth, rightdepth) + 1; } }
相关文章推荐
- Resin配置SSL双向认证
- 前端的小玩意(1)input 只允许输入整数 + 用逗号进行三位分割
- ElasticSearch学习四:集群搭建实例
- java的Comparator接口如何对指定类型进行排序。
- Apache Flume1.6.0安装与部署
- Pycharm的快捷键风格设置
- 类的设计原则
- docker –-link 解析
- 算法牛人,原创
- sambaf服务器配置(上)
- Matlab 程序性能(计算速度)分析方法
- mac隐藏和显示隐藏文件
- android 获取手机的网络状态
- 模块和包,包管理器,调试-02
- Picasso设置圆角
- House Robber II
- 基于JS代码实现导航条弹出式悬浮菜单
- Android传感器(五):线性加速度传感器
- CSS JavaScript DOM写的仿谷瀑网搜索导航
- CSS JavaScript DOM写的仿谷瀑网搜索导航