[Lintcode] #97 二叉树的最大深度
来源:互联网 发布:宋仲基五官知乎 编辑:程序博客网 时间:2024/05/23 01:11
给定一个二叉树,找出其最大深度。
二叉树的深度为根节点到最远叶子节点的距离。
样例
给出一棵如下的二叉树:
1 / \ 2 3 / \ 4 5
这个二叉树的最大深度为3
.
/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left = this.right = null; * } * } */public class Solution { /** * @param root: The root of binary tree. * @return: An integer. */ public int maxDepth(TreeNode root) { // write your code here if (root == null)return 0;return 1 + Math.max(maxDepth(root.left), maxDepth(root.right)); }}
阅读全文
0 0
- lintcode 97 二叉树的最大深度
- [Lintcode] #97 二叉树的最大深度
- LintCode:二叉树的最大深度
- 二叉树的最大深度(LintCode)
- lintcode,二叉树的最大深度
- LintCode-二叉树的最大深度
- lintcode 二叉树的最大深度
- LintCode 二叉树的最大深度
- 二叉树的最大深度-LintCode
- LintCode 二叉树的最大深度
- [lintcode]二叉树的最大深度
- 二叉树的最大深度-LintCode
- [LintCode]97.二叉树的最大深度
- lintcode二叉树的最大深度
- lintcode 97.二叉树的最大深度
- LintCode-剑指Offer-(97)二叉树的最大深度
- Lintcode-递归-97 二叉树的最大深度
- lintcode——二叉树的最大深度
- 函数指针作为某个函数的参数及定义函数指针
- 【Unity Shader入门精要】— Unity Shader基础
- mongodb字段修改 String类型的日期修改为datetime类型
- HDU-1231 最大连续子序列
- [NLP论文阅读] The Fixed-Size Ordinally-Forgetting Encoding Method for Neural Network Language Models
- [Lintcode] #97 二叉树的最大深度
- WebRTC
- Angularjs自定义服务~使用Module的factory方法
- 过滤敏感词
- error lnk1158 无法运行cvtres.exe
- 满纸荒唐言 一把辛酸泪
- 新闻头条案例工具类
- 大数据在安防领域的9个发展趋势
- HDU-1257 最少拦截系统