Maximum Depth of Binary Tree
二叉树最大深度的递归实现。
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
import java.lang.*;
public class Solution {
public int maxDepth(TreeNode root) {
int depth1;
int depth2;
if(root == null) return 0;
//左子树的深度
depth1 = maxDepth(root.right);
//右子树的深度
depth2 = maxDepth(root.left);
return Math.max(depth1,depth2)+1;
}
}
Maximum Depth of Binary Tree的更多相关文章
- [LintCode] 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][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...
- LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...
- Leetcode | Minimum/Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- 104. Maximum Depth of Binary Tree(C++)
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...
随机推荐
- Oracle查询数据库中的所有表
SELECT A.TABLE_NAME 表英文名, A.TAB_COMMENTS 表中文名, A.COLUMN_ID 序号, A.COLUMN_NAME 英文名, ...
- 【转】File类应用 - FilenameFilter 和 FileFilter
FilenameFilter & FileFilter FilenameFilter 和 FileFilter 都是用来过滤文件,例如过滤,以.jpg或者.java结尾的文件,通过看他们的源码 ...
- 在VBA中调用excel函数
以前不太会用VBA时,都是在excel中使用函数来计算一些数据.毕竟函数不如代码,效率比较低.所以,就学着怎么在VBA中引用Excel函数.平时我用得比较多的函数就是countif和sumif函数.1 ...
- how a 程序猿 doubled his salary?
One thing i can say, no matter what position i was in or what was my salary, i never stopped studyin ...
- the king of fighter
wim 学习部分摘自coolshell http://coolshell.cn/articles/5426.html 基本式 i → Insert 模式,按 ESC 回到 Normal 模式. x → ...
- 入住cnblogs第一篇随笔 Hello, world!
在网上搜索计算机参考资料时经常看到各位大神的博客,甚是神往.今天我也在这里安家,记录自己的学习过程,也同各位共勉. 第一篇随笔,就用来测试一下这里的文本编辑器吧. //The C language # ...
- JSP自定义标签——调用数据库(通过id号搜索相关信息)
一.创建新表(假设在master数据库下新建) 二.连接数据库 开始-->控制面板-->管理工具-->数据源-->系统DSN-->添加-->SQL Server-- ...
- C/C++代码覆盖率生成
初始状态下只有一个源代码文件 nosoul@linux:testCov> ls test.c nosoul@linux:testCov> 第一步:编译.链接.执行可执行文件 gcc -o ...
- 通过HttpWebRequest请求与HttpWebResponse响应方式发布接口与访问接口
一.API接口的编码 1.首页的页面代码: protected void Page_Load(object sender, EventArgs e) { /* * 请求路径:http://xxxx/i ...
- ssh整合--struts
一 struts(jar+web.xml+struts.xml+Action) 1import min_jars-------struts-2.3.20.3-all(struts2-blank.war ...