题目描述

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.
 
int run(TreeNode *root){
if (root == nullptr) return ;
if (root->left == nullptr)
{
return run(root->right) + ;
}
if (root->right == nullptr)
{
return run(root->left) + ;
}
int leftDepth = run(root->left);
int rightDepth = run(root->right);
return (leftDepth <= rightDepth) ? (leftDepth + ) : (rightDepth + );
}

1、minimum-depth-of-binary-tree的更多相关文章

  1. leetcode -day17 Path Sum I II &amp; Flatten Binary Tree to Linked List &amp; Minimum Depth of Binary Tree

    1.  Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such tha ...

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

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

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

  5. 【LeetCode练习题】Minimum 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】Minimum Depth of Binary Tree 二叉树的最小深度 java

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

  7. LeetCode My Solution: Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Total Accepted: 24760 Total Submissions: 83665My Submissions Given a bi ...

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

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

  9. LeetCode: Minimum Depth of Binary Tree 解题报告

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  10. 【LeetCode】111. Minimum Depth of Binary Tree (2 solutions)

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

随机推荐

  1. python自动化测试入门篇-jemter连接mysql数据库

    jmeter对数据库的操作主要包括以下几个步骤:1.导入mysqlde jdbc的jar包:2.创建数据库连接配置:3.线程组添加jdbc request;4.启动按钮,添加查看结果树 一.准备好驱动 ...

  2. 使用ssm(spring+springMVC+mybatis)创建一个简单的查询实例(一)

    梳理下使用spring+springMVC+mybatis 整合后的一个简单实例:输入用户的 ID,之后显示用户的信息(此次由于篇幅问题,会分几次进行说明,此次是工程的创建,逆向生成文件以及这个简单查 ...

  3. 诡异的bug!!

    在我些项目的时候,命名从来没有用过 font 元素,但是打开 Chrome 浏览器查看元素时,总是 font 元素???而且写的 <span class= "xxx"> ...

  4. java使用valueOf的方法反转字符串输出

    public class FanZhuan { public static void main(String[] args) { String s = "987654321088123abo ...

  5. Linux c读取任意大小文件的所有数据

    代码如下,执行完之后被分配的动态内存的指针会保存到result中.由于是动态分配内存,读取内容不再使用之后注意用free 释放掉,如不明白,请多搜索以下动态内存分配的资料. #include < ...

  6. python之路-----多线程与多进程

    一.进程和线程的概念 1.进程(最小的资源单位): 进程:就是一个程序在一个数据集上的一次动态执行过程.进程一般由程序.数据集.进程控制块三部分组成. 程序:我们编写的程序用来描述进程要完成哪些功能以 ...

  7. 管理商品demo

    1.写一个管理商品的程序# 1.商品存在文件里面# 2.添加商品的时候,商品存在的就不能添加了,数量只能是大于0的整数,价格可以是小数.整数,但是只能是大于0的# 商品名称# 商品价格# 商品数量# ...

  8. Erlang ETS Table

    不需要显示用锁,插入和查询时间不仅快而且控制为常量,这就是Erlang的ETS Table. 为什么而设计? Erlang中可以用List表达集合数据,但是如果数据量特别大的话在List中访问元素就会 ...

  9. tcl中数字加减的怪异现象

    今天做一个数字转换的测试,发现一个比较怪异的错误: 这样子不能直接处理字符串了. 在编译器中进行处理: 发现除了8和9,其他的字符前面有0的话都可以! 所以需要对数字小于10的数进行屏蔽,或者对09  ...

  10. Task使用

    Task task1 = Task.Factory.StartNew(() => { Console.WriteLine("Hello,task started by task fac ...