LeetCode - Maximum Depth of Binary Tree
2016-01-10 10:48
218 查看
题目:
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.
思路:
递归
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.
思路:
递归
package treetraversal; public class MaximumDepthOfBinaryTree { public int maxDepth(TreeNode root) { if (root == null) return 0; return Math.max(1 + maxDepth(root.left), 1 + maxDepth(root.right)); } }
相关文章推荐
- 按钮触摸事件
- 从零开始写javaweb框架笔记9-细节完善与代码优化-完善控制器层
- MIR Flickr图像数据集
- 外观模式
- cf 337 div2 c
- Git(三)远程仓库操作
- ubuntu初学
- LeetCode - Binary Tree Zigzag Level Order Traversal
- Activity启动过程源码分析
- 提示音量增加事件
- Linux从程序到进程
- centos install(160112更新)
- oracle 解锁用户和修改密码
- 远程桌面问题
- 通过SecureCRT访问亚马逊Amazon EC2主机
- 最大堆的插入/删除/调整/排序操作(图解+程序)(JAVA)
- 关于Pascal和二项式系数
- 高阶函数应用
- c语言二进制文件加密
- JPA调用存储过程的方法