题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/

111. Minimum Depth of Binary Tree

My Submissions

Question
Total Accepted: 94580 Total
Submissions: 312802 Difficulty: Easy

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

Subscribe to see which companies asked this question

Show Tags
Show Similar Problems
Have you met this question in a real interview? 

Yes

 

No

Discuss

    求一棵二叉树。离根近期的叶子的高度。递归找出两棵子树的最小高度加一便可求解。

    我的AC代码

public class MinimumDepthofBinaryTree {

	public int minDepth(TreeNode root) {
if(root == null) return 0;
return height(root);
} private int height(TreeNode root){
if(root.left == null && root.right == null) return 1;
else if(root.left == null) return height(root.right) + 1;
else if(root.right == null) return height(root.left) + 1;
return Math.min(height(root.left), height(root.right)) + 1;
}
}

LeetCode OJ Minimum Depth of Binary Tree 递归求解的更多相关文章

  1. LeetCode OJ——Minimum Depth of Binary Tree

    http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ 贡献了一次runtime error,因为如果输入为{}即空的时候,出现了c ...

  2. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  3. [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)

    [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...

  4. [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 ...

  5. [LeetCode] 111. Minimum Depth of Binary Tree 二叉树的最小深度

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  6. Leetcode 111 Minimum Depth of Binary Tree 二叉树

    找出最短的从叶子到根的路径长 可以回忆Maximum Depth of Binary Tree的写法,只不过在!root,我把它改成了10000000,还有max函数改成了min函数,最后的值如果是1 ...

  7. Java [Leetcode 111]Minimum Depth of Binary Tree

    题目描述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...

  8. LeetCode 111. Minimum Depth of Binary Tree (二叉树最小的深度)

    Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...

  9. LeetCode(37)-Minimum Depth of Binary Tree

    题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...

随机推荐

  1. React Native - 5 ListView实现图文混排

    首先在根目录下建一个images文件夹,准备好图片 准备datasource 准备图片资源 准备renderRow方法 记得要import相应的类,ListView, Image, Touchable ...

  2. PL/SQL 11.6 注册码

    PL/SQL Developer 下载地址:Download PL/SQL Developer 11.0.6 注册码 Product Code:4t46t6vydkvsxekkvf3fjnpzy5wb ...

  3. 多线程IO模型

    服务端编程,首要问题是选取IO模型.即如何处理大量连接,服务更多的客户端? 我们最早有2种解法,各有不足: 1.阻塞IO,每个连接都需要一个线程. 随着连接数增多,线程数剧增,系统开销太大. 2.非阻 ...

  4. Eclipse Qt开发环境的建立

    1.下载Eclipse目前Eclipse+CDT已经可以集成下载了,好像优化过了,速度还比较快.下载的地址是:http://www.eclipse.org/downloads/,选择“Eclipse ...

  5. JQuery动态添加多个tab页标签

    jQuery是一个兼容多浏览器的js库,核心理念是write less,do more(写的更少,做的更多),jQuery使用户能更方便地处理HTML documents.events.实现动画效果, ...

  6. Java使用Redis初探

    Redis的相关概念不做介绍了,大家也可以先了解下Memcached,然后比较下二者的区别,就会有个整体的印象. 服务器端通常选择Linux , Redis对于linux是官方支持的,使用资料很多,需 ...

  7. 在CentOS6或RHEL6恢复上ext4文件系统误删除的文件

    首先说明: [root@CentOS6 ~]# rm -rf / //这条命令不可以执行 [root@CentOS6 ~]# rm -rf /* //这条命令可以执行,别去试 ext4文件系统上误删除 ...

  8. BZOJ 3343:教主的魔法(分块)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=3343 [题目大意] 给出一个数列,有区间加法操作,询问区间大于等于c的数字个数 [题解 ...

  9. 20162318 2016-2017-2《Java程序设计》课堂实践项目

    20162318 2016-2017-2<Java程序设计>课堂实践项目 String类的使用 在String类中有一种split的方法.它可以把字符串分割为好几个小的字符串. 实践内容: ...

  10. Problem F: 尖兵

    #include<stdio.h> struct man{ ]; int grade; }; int main(void) { int t; int i,j,n; ],max; scanf ...