原题

寻找二叉树最短深度

这里用了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. GNU自动化工具使用全过程详解,以及在线手册

    [root@localhost test3]# cat add.h#ifndef _ADD_H_#define _ADD_H_ extern int add(int, int); #endif [ro ...

  2. Windows窗体原理及控件WM_DRAWITEM和子类化重绘演示文件

    http://download.csdn.net/detail/wenzhou1219/6783959

  3. csdn token

    http://download.csdn.net/download/pp_haitun/9614126 http://dl.download.csdn.net/down11/20160826/28b9 ...

  4. Python正则表达式进阶-零宽断言

    1. 什么是零宽断言 有时候在使用正则表达式做匹配的时候,我们希望匹配一个字符串,这个字符串的前面或后面需要是特定的内容,但我们又不想要前面或后面的这个特定的内容,这时候就需要零宽断言的帮助了.所谓零 ...

  5. 对新数据库使用 Code First

    如果使用的是 Visual Studio 2010,还需要安装 Nuget 1.创建应用程序 简单起见,我们将构建一个使用 Code First 执行数据访问的基本控制台应用程序. 打开 Visual ...

  6. 【Web前端Talk】“用数据说话,从埋点开始”-带你理解前端的三种埋点

    埋点到底是什么呢? 引用自百科的原话是,埋点分析网站分析的一种常用的数据采集方法.因此其本质是分析,但是靠什么分析呢?靠埋点得到的数据.通俗来讲,就是当我想要在某个产品上得到用户的一些行为数据用来分析 ...

  7. SYN4102型 GPS同步时钟

    SYN4102型  GPS同步时钟 产品概述 SYN4102型GPS同步时钟是由西安同步电子科技有限公司精心设计.自行研发生产的一款高精度锁相时钟频率源,接收GPS信号,使恒温晶振输出频率同步于GPS ...

  8. Java---使用EWS读取exchange邮件

    第一步: 下载EWS API相关包: 从如下路径下载EWS API包:http://code.msdn.microsoft.com/Exchange-EWS-Java-API-12-1a5a1143 ...

  9. 简易数据分析 04 | Web Scraper 初尝--抓取豆瓣高分电影

    这是简易数据分析系列的第 4 篇文章. 今天我们开始数据抓取的第一课,完成我们的第一个爬虫.因为是刚刚开始,操作我会讲的非常详细,可能会有些啰嗦,希望各位不要嫌弃啊:) 有人之前可能学过一些爬虫知识, ...

  10. vuex中使用对象展开运算符

    使用场景 当需要进行vuex进行数据状态管理的时候,会使用到mapGetters,mapState,还有自身的计算属性的时候,这个时候就会用到这个了! 1.首先需要安装 npm install bab ...