104MaximumDepthofBinaryTree
2016-05-20 15:20
183 查看
使用递归比较左右子树的高度,该树的最大高度为max(max(left), max(right)+1
该题与交换左右子树类似
该题与交换左右子树类似
public class Solution { public int maxDepth(TreeNode root) { int lmax, rmax; if(root == null) { return 0; } lmax = maxDepth(root.left); rmax = maxDepth(root.right); if(lmax >= rmax) return lmax+1; else return rmax+1; } }
相关文章推荐
- HDU1879(水Kruskal、Prim)
- Android中Activity启动过程探究
- Copy & MutableCopy
- 安卓代码迁移:ActionBarActivity: cannot be resolved to a type
- osgOcean 水面效果
- Tomcat调优总结
- js查询
- js打印Log
- 用Kibana和logstash快速搭建实时日志查询、收集与分析系统
- C语言的Socket编程例子(TCP和UDP)
- (转)IIS设置优化(需根据服务器性能,调整具体参数值)
- tomcat的connector与container原理分析(二)
- centos 下面修改mysql的root密码
- js定时器
- js插入删除-1
- ios调用js
- 关于C++ vector<S>使用时,错误 5 error C2719: “_Val”: 具有 __declspec(align('16')) 的形参将不被对齐
- s2sh框架整合详细配置-xml方式
- Citrix Supportability Pack介绍
- Spring注解@Component、@Repository、@Service、@Controller区别