Leetcode-maximum-depth-of-binary-tree
2016-06-26 16:27
441 查看
题目描述
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.
public class Solution {
public int maxDepth(TreeNode root) {
if(root == null)
return 0;
else{
int left = maxDepth(root.left)+1;
int right = maxDepth(root.right)+1;
return Math.max(left, right);
}
}
}
递归思想。
相关文章推荐
- URL和URI的区别
- postgresql----ANY/SOME&&ALL
- hdu 4525(数学)
- 面试必备
- Android Studio使用gradle-experimental构建NDK工程(无需Android.mk、Application.mk文件)
- strcpy函数的实现
- 【DAY20】Socket编程的补充2
- gitlab工作流程简介
- Qt5以上的建立空Qt项目时
- 求图中最短路径算法之Floyd-Warshall算法——C++实现
- Hadoop源码 YarnRPC通信框架
- 36. In Depth Magento System Configuration
- iOS开发中WebView的基本使用方法简介
- 【DAY19】 socket编程的补充
- 关于MySQL的各种总结
- Could not find Android-Validator-master.apk!
- 多线程(一) —— 传统线程(Thread)的创建和计时器(Timer)
- hrbust 1000 A + B Problem【600篇原创纪念】
- java中使用 正则 抓取邮箱
- C语言break语句