Maximum Depth of Binary Tree
2016-03-31 10:24
381 查看
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) { int deep=0; if(root!=null){ int lchilddeep=maxDepth(root.left); int rchilddeep=maxDepth(root.right); deep=lchilddeep>rchilddeep?lchilddeep+1:rchilddeep+1; } return deep; } }
相关文章推荐
- 开发人员、程序员与计算机科学家三者之间的区别
- 只有程序员看的懂的面试圣经|如何拿下编程面试
- 下一次技术面试时要问的 3 个重要问题
- 书评:《算法之美( Algorithms to Live By )》
- 程序员必备,程序员四大忌
- 程序员们,做好你手里的俩份试卷
- 动易2006序列号破解算法公布
- 程序员必备的10大健康装备! 我们要工作更要健康!
- Ruby实现的矩阵连乘算法
- C#插入法排序算法实例分析
- 一篇关于程序员性格的文章第1/3页
- PHP程序员面试 切忌急功近利(更需要注重以后的发展)
- 超大数据量存储常用数据库分表分库算法总结
- C#数据结构与算法揭秘二
- C#冒泡法排序算法实例分析
- 8种类型极品程序员,不知你属于哪一种?
- 算法练习之从String.indexOf的模拟实现开始
- C#算法之关于大牛生小牛的问题
- C#实现的算24点游戏算法实例分析
- 程序员编程从初级到中级的10个秘诀