LeetCode-104.Maxinum Depth of Binary Tree
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.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7]
,
3
/ \
9 20
/ \
15 7
return its depth = 3.
public int maxDepth(TreeNode root) {//树 递归 my
if(null==root){
return 0;
}
int ld=maxDepth(root.left);
int lr = maxDepth(root.right);
int d = ld>lr?(ld+1):(lr+1);
return d;
}
还可以使用BFS
相关题
二叉树的最小深度 LeetCode111 https://www.cnblogs.com/zhacai/p/10598843.html
LeetCode-104.Maxinum Depth of Binary Tree的更多相关文章
- LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- [LeetCode] 104. Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- (二叉树 BFS DFS) leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- LeetCode 104. Maximum Depth of Binary Tree (二叉树的最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- LeetCode 104. Maximum Depth of Binary Tree
Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...
- leetcode 104 Maximum Depth of Binary Tree ----- java
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Java [Leetcode 104]Maximum Depth of Binary Tree
题目描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...
- Leetcode 104. Maximum Depth of Binary Tree(二叉树的最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- Leetcode 104 Maximum Depth of Binary Tree python
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
随机推荐
- hadoop核心逻辑shuffle代码分析-map端
首先要推荐一下:http://www.alidata.org/archives/1470 阿里的大牛在上面的文章中比较详细的介绍了shuffle过程中mapper和reduce的每个过程,强烈推荐先读 ...
- Android设计和开发系列第二篇:Navigation Drawer(Design)
Navigation Drawer Creating a Navigation Drawer The navigation drawer is a panel that transitions in ...
- kafka---->kafka的使用(一)
今天我们来学习一下kafka的简单的使用与配置.世上有可以挽回的和不可挽回的事,而时间经过就是一种不可挽回的事. kafka的安装配置 一.kafka的使用场景 活动跟踪:网站用户与前端应用程序发生交 ...
- CacheDependency 的使用方法
//创建缓存依赖项 CacheDependency dep = new CacheDependency(fileName); //创建缓存 HttpContext.Current.Cache.Inse ...
- python函数定义语法总结
见下面代码及注释: def calc(value): sum=0 for m in value: sum=sum+m return sum data=[1,2,3,4,5,6,7,8,9,10] pr ...
- ogg 12c OGG-01163
数据同步报错: 2017-07-03 12:44:36 ERROR OGG-01163 Oracle GoldenGate Delivery for Oracle, rora_t1.prm: Bad ...
- jconsole连接远程Tomcat应用
一.环境信息 远程tomcat:linux 64位 centos 7 上tomcat 8 本机:windows7 二.步骤 linux上,在tomcat安装目录的bin下,新建setenv.sh,内容 ...
- node爬虫(转)
我们先来看看今天的目标: mmjpg.com的美腿频道下的图片 一.实现步骤 使用superagent库来获取页面分析页面结构,使用cheerio 获取有效信息保存图片到本地开撸不断优化 这儿我们用到 ...
- Visual Studio 2013附加进程调试IE加载的ActiveX Control无效解决方法
默认Attach to选择了Automatically determine the type of code to debug,显示Native Code.但附加进程到iexplore.exe断点无法 ...
- Linux批量杀死进程
杀死进程在linux中使用kill命令了,我们可以下面来给各位介绍一篇关于Linux下批量杀死进程的例子,希望此例子可以对各位同学带来帮助的哦. 批量杀死包含关键字“php-fpm”的进程. kill ...