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. SQL使用技巧

    SQLServer 数据库变成单个用户后无法访问问题的解决方法 USE master; GO DECLARE @SQL VARCHAR(MAX); SET @SQL='' SELECT @SQL=@S ...

  2. Spring入门教程:通过MyEclipse开发第一个Spring项目

    Animal.java package com.project; public class Animal { private String name; public String getName() ...

  3. JS 全屏代码

    // 推断各种浏览器,找到正确的方法 function launchFullscreen(element) { if(element.requestFullscreen) { element.requ ...

  4. php Date()函数输出中文年月日时分秒

    当然了,PHP的DATE函数是不可能直接输出中文的年月日的,但可以用下面这种方法自己写一个函数. 代码如下 复制代码 function today(){ date_default_timezone_s ...

  5. R语言编程艺术#04#数据框(data.frame)

    从直观上看,数据框类似矩阵

  6. struts2 + urlrewrite 整合注意事项

    这几天业余时间在玩百度云,百度的云还是不错的,但是对于我这样的.NET程序员,有点不公平,没有.net虚机,不过也不是百度一家没有,基本都没有,有的都是那种开放云,自已在云端来部署安装软件的. 所以也 ...

  7. 阿里巴巴CI:CD之分层自动化实践之路

    阿里巴巴CI:CD之分层自动化实践之路 2018-05-30 摘自:阿里巴巴CI:CD之分层自动化实践之路 目录 1 自动化  1.1 为什么要做自动化?  1.2 自动化的烦恼  1.3 自动化的追 ...

  8. .so.x不是符号连接

    去到这个目录下查看,会发现有多个.so.x文件.x是版本号的区别.将它们动态软连接在一起就可以了 参考这个博客

  9. 【iCore4 双核心板_ARM】例程五:SYSTICK定时器 实验——定时点亮LED

    实验原理: 通过STM32的三个GPIO口驱动三色LED的三个通道,设定GPIO为推挽输出模式,采 用灌电流方式与LED连接,输出高电平LED灭,输出低电平LED亮,通过系统定时器实现 1s定时,每秒 ...

  10. Java、Linux、Win 快速生成指定大小的空文件

    Linux dd 命令: dd if=/dev/zero of=<fileName> bs=<一次复制的大小> count=<复制的次数> 生成 50 MB 的空文 ...