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.

Note: A leaf is a node with no children.

Example:

Given binary tree [3,9,20,null,null,15,7],


return its minimum depth = 2.

求最小的深度,二叉树,这道题目我认为数据是有问题的,所以有176个踩,

c++

class Solution {
public:
int minDepth(TreeNode* root) {
if(root==NULL) return ;
int lmin =;
int rmin =;
if(root->left!=NULL)
lmin = minDepth(root->left);
if(root->right!=NULL)
rmin = minDepth(root->right);
if(lmin==)
return rmin+;
if(rmin==)
return lmin+;
return min(lmin,rmin)+; }
};

LeetCode 112 Minimum Depth of Binary Tree的更多相关文章

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

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

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

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

  3. LeetCode OJ Minimum Depth of Binary Tree 递归求解

        题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 111. Minimum Depth of Binary T ...

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

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

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

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

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

  8. leetcode 111 minimum depth of binary tree

    problem description: Given a binary tree, find its minimum depth. The minimum depth is the number of ...

  9. 【leetcode】Minimum Depth of Binary Tree

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

随机推荐

  1. sublime text 3-right click context menu

    dd a system wide windows explorer button " Edit with Sublime" similar to how Notepad++ doe ...

  2. 12C -- 创建RMAN备份用户

    1.NON-CDB环境 SQL> create user backup_admin identified by backup_admin default tablespace users; SQ ...

  3. Android 组件系列-----Activity生命周期

    本篇随笔将会深入学习Activity,包括如何定义多个Activity,并设置为默认的Activity.如何从一个Activity跳转到另一个Activity,还有就是详细分析Activity的生命周 ...

  4. Json字符串转DataTable

    /// <summary> /// 将json转换为DataTable /// </summary> /// <param name="strJson" ...

  5. 【工具】我的Git学习日志

    使用github一段时间,一直使用的是可视化工具,配合公司转用git,提前联系下git的命令. 安装 windows上安装git 从git for windows下载安装包,我下的是Git-2.13. ...

  6. 【Java】浅谈HashMap

    HashMap是常用的集合类,以Key-Value形式存储值.下面一起从代码层面理解它的实现. 构造方法 它有好几个构造方法,但几乎都是调此构造方法: public HashMap(int initi ...

  7. tail -f 实时查看日志文件 linux查看日志后100行

    tail -f 实时查看日志文件 tail -f 日志文件logtail - 100f 实时查看日志文件 后一百行tail -f -n 100 catalina.out linux查看日志后100行搜 ...

  8. 实现div里的img图片水平垂直居中

    body结构 <body> <div> <img src="1.jpg" alt="haha"> </div> ...

  9. Java 分布式和集中式理解

    文章转载自:https://blog.csdn.net/youanyyou/article/details/79406507

  10. <王二的经济学故事>读书笔记

    不是简单地用价格把供需弄平衡就完事了,座位分配给谁同样重要 一个成功的社会必须要有成功的人,必须要给成功的人应得的回报 需求曲线向下倾斜,价格越高需求越少 先来的都是那些时间最不值钱的 无论收入分配差 ...