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.

C++

class Solution {
public:
//run:12ms memory:884k
int run(TreeNode *root) {
if (NULL == root) return 0;
if (NULL == root->left && NULL == root->right) return 1;
if (NULL == root->left) return run(root->right) + 1;
else if(root->right == NULL) return run(root->left) + 1;
else return min(run(root->left),run(root->right)) + 1;
}
};

minimum-depth-of-binary-tree leetcode C++的更多相关文章

  1. Minimum Depth of Binary Tree ——LeetCode

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

  2. Minimum Depth of Binary Tree [LeetCode]

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

  3. Minimum Depth of Binary Tree leetcode java

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

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

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

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

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

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

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

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

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

  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 My Solution: Minimum Depth of Binary Tree

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

随机推荐

  1. 内部类访问外部类成员变量,使用外部类名.this.成员变量

    public class Outer { private int age = 12; class Inner { private int age = 13; public void print() { ...

  2. phpstorm一直 updating indices刷新

    解决方法: File-> 选中 Invalidate Caches/Restart  ->选中 Invalidate Caches/Restart

  3. Windows 10 64位操作系统 下安装、配置、启动、登录、连接测试oracle 11g

    一.下载oracle安装包 1:详细下载安装版本可见官网:https://www.oracle.com/technetwork/database/enterprise-edition/download ...

  4. 解决navicat 导出excel数字为科学计数法问题

    1.原因分析      用程序导出的csv文件,当字段中有比较长的数字字段存在时,在用excel软件查看csv文件时就会变成科学技术法的表现形式.     其实这个问题跟用什么语言导出csv文件没有关 ...

  5. openldap集成ssh 登录

    一 安装nslcd服务 yum install nss-pam-ldapd 二.修改vi /etc/nslcd.conf这个配置文件 修改uri 和base的值 改为你的ldap的地址和用户名 三.  ...

  6. Appium WebView控件定位

    背景 移动应用可以粗分为三种:原生应用(native app), 网页应用(web app,或HTML5 app),以及它们的混血儿--混合模式移动应用(hybrid app). 什么是Hybrid ...

  7. 自动化测试报告----allure2(一)

    以前都是使用TestNG自带的报告.jenkins中的报告等但没有个性化装饰报告,然而接触过allure2后发现原来报告还可以这么酷,接下来就带大家一起看一下allure2 报告炫在哪里? 我们先看如 ...

  8. 『Python』面向对象(二)

    继承 继承的语法 class Animal(object): def __init__(self,name): self.__name = name class Dog(Animal): kind = ...

  9. P7600-[APIO2021]封闭道路【堆,dp】

    正题 题目链接:https://www.luogu.com.cn/problem/P7600 题目大意 给出\(n\)个点的一棵树,边有边权,对于每个\(k\)求去掉最小边权和的点使得每个点的度数都不 ...

  10. 51nod1600-Simple KMP【SAM,树链剖分】

    正题 题目链接:http://www.51nod.com/Challenge/Problem.html#problemId=1600 题目大意 给出一个字符串\(s\),每次在最后插入一个字符后求它的 ...