原题

寻找二叉树最短深度

这里用了dfs,beat 100%,4ms

class Solution
{
public:
int minDepth(TreeNode *root, int minNum = 0)
{
if (root == NULL)
{
return minNum == 0 ? minNum : 999999;
}
if (root->left == NULL && root->right == NULL)
return minNum + 1;
return min(minDepth(root->left, minNum + 1),
minDepth(root->right, minNum + 1));
}
};

[leetcode] 111.Mininum Depth of Binary Tree (Easy)的更多相关文章

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

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

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

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

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

  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 111 minimum depth of binary tree

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

  6. 【leetcode】Minimum Depth of Binary Tree (easy)

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

  7. leetcode 111 Minimum Depth of Binary Tree ----- java

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

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

  9. (二叉树 BFS DFS) 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 ...

随机推荐

  1. MiTeC System Information Component Suite 10.9.2 D5-XE3 Full Source

    The most complex system information probe in Delphi world, it consists of many standalone components ...

  2. 【Qt】无边框窗体中带有ActiveX组件时的一个BUG

    无意中发现的一个BUG,Qt5.1.1正式版首先创建一个GUI工程,拖入一个QAxWidget控件(为了使ActiveX生效,需要在.pro文件中加入CONFIG += qaxcontainer)接着 ...

  3. Windows 64 位下安装 psyco 1.6

    用 eclipse 运行 python 的时候,第一行总是有红色提示:没有安装 psyco,程序可以正常运行但是会有一点慢.于是就干脆装上吧,红色的提示还是越少越舒服. 百度了一下,在这里,http: ...

  4. Java基础(四) StringBuffer、StringBuilder原理浅析

    StringBuilder与StringBuffer作用就是用来处理字符串,但String类本身也具备很多方法可以用来处理字符串,那么为什么还要引入这两个类呢? 关于String的讲解请看Java基础 ...

  5. Java动态规划

    1. 介绍 动态规划典型的被用于优化递归算法,因为它们倾向于以指数的方式进行扩展.动态规划主要思想是将复杂问题(带有许多递归调用)分解为更小的子问题,然后将它们保存到内存中,这样我们就不必在每次使用它 ...

  6. Java Collection秋招复习

    抽象类和接口的区别 我们先来看一下抽象类 * @auther draymonder */ public abstract class AbstractClassTest { private int T ...

  7. 你竟然没用 Maven 构建项目?

    一年前,当我和小伙伴小龙一起做一个外包项目的时候,受到了严重的鄙视.我那时候还不知道 Maven,所以搭建项目用的还是最原始的方式,小龙不得已在导入项目的时候花了很长时间去下载项目依赖的开源类库. 出 ...

  8. 【静态NAT】 为什么子网可以ping父网,但是父网ping不通子网?

    为什么子网可以ping父网,但是父网ping不通子网? 这就好比在公网中ping一个192.168.0.x的子网,roter无法找到这个子网的地址,所以会把package丢掉. 如何解决呢,可以在路由 ...

  9. Linux实例/etc/fstab文件配置错误导致系统启动异常

    Centos 7.3系统 问题现象: 阿里云ECS升级配置后重启,SSH连接不上.登录控制台远程连接ECS,出现以下界面.  提交工单阿里云反馈:https://help.aliyun.com/kno ...

  10. Spring中的配置文件文件位置

    在Java开发中,一般在Spring框架中,classpath的位置是指src下,在IDEA中一般是指resource中 配置文件 位置:任意,开发中一般在classpath下(src) 名称:任意, ...