求二叉树的最小深度:

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int minDepth(TreeNode* root) { if (root == NULL) return ;
int l = minDepth(root->left);
int r = minDepth(root->right);
if (l == ) return r+; //******r+1
if (r == ) return l+;
return min(l,r)+; }
};

【easy】111. Minimum Depth of Binary Tree求二叉树的最小深度的更多相关文章

  1. LeetCode OJ: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 (二叉树最小的深度)

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

  3. (二叉树 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 ...

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

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

  5. 【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 ...

  6. 【LeetCode】111. Minimum Depth of Binary Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 [LeetCode] 题目地址 ...

  7. 【一天一道LeetCode】#111. Minimum Depth of Binary Tree

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

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

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

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

随机推荐

  1. iOS开发基础-九宫格坐标(4)

    对iOS开发基础-九宫格坐标(3)的代码进行进一步优化. 新建一个 UIView 的子类,并命名为 WJQAppView ,将 appxib.xib 中的 UIView 对象与新建的视图类进行关联. ...

  2. .net core2.1 三层中使用Autofac代替原来Ioc

    首先,现有的三层项目的结构 其中  Repository public interface IPersonRepository { string Eat(); } public class Perso ...

  3. gorose使用示例

    package main import ( "fmt" "github.com/gohouse/gorose" //import Gorose _ " ...

  4. Sql Server2008如何让外网访问自己的数据库

    1.打开 Sql Server配置管理器 2.修改Sql Server网络配置,将Tcp/IP协议修改为“已启用” 3.重启Sql Server服务即可(如果不知道怎么重启Sql Server服务,重 ...

  5. js实现小功能 动态赋值

  6. hMailServer 邮件服务器搭建

    HMailServer是一个运行于微软Windows系统.基于GPL授权.免费的电子邮件系统:支持常见的电子邮件协议SMTP.POP3.IMAP:可以很容易地与许多现有的网络邮件系统集成和二次开发:具 ...

  7. Vue.js指令实例

    v-if  v-else  v-show v-if 根据表达式的值的真假条件渲染元素. v-else 不需要表达式.前一兄弟元素必须有 v-if 或 v-else-if v-show 根据表达式之真假 ...

  8. CODEVS 3546 矩阵链乘法

    http://codevs.cn/problem/3546/ 题目 给定有n个要相乘的矩阵构成的序列(链)<A1,A2,A3,.......,An>,要计算乘积A1A2.....An.一组 ...

  9. Java多线程处理某个线程超时的问题

    ExecutorService exec = Executors.newFixedThreadPool(4); List<Future<Integer>> futures = ...

  10. Day 4 测试(QwQ 表示没考好 未完待续。。。 可能要过一段时间才会更

    #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #i ...