LeetCode题解:Maximum Depth of Binary Tree
2016-02-27 19:52
495 查看
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.
题意:给定二叉树,找出最大深度
思路:DFS
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
题意:给定二叉树,找出最大深度
思路:DFS
public class Solution { public int maxDepth(TreeNode root) { if(root == null){ return 0; } return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1; } }
相关文章推荐
- UVA 11627 Slalom 二分 模拟
- 《JAVA编程思想》日志(三)------操作符
- Spark源码分析之九:内存管理模型
- HDU 3078 Network (LCA)
- mysql Slave_IO_Running:NO(解决方法)
- 对lrucache的解读
- 模板_LinkCutTree
- Activity堆栈详解
- CodeForces Manthan, Codefest 16 A Ebony and Ivory 扩展欧几里德(其实暴力直接搞就可以)
- PED结构获取进程路径和命令行地址
- EditPlus配置编译运行Java程序
- 创建、删除文件和文件夹的命令
- OC 数据持久化存储
- JavaScript全讲-架构原则解析
- 使用Bmob后端云遇到的坑
- static_cast, dynamic_cast, reinterpret_cast, const_cast区别比较
- Struts2入门~工作原理及访问Servlet API
- STL之vector
- 紫书 p48 例题 回文词
- 可输入下拉框的实现