题目描述

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.
 
int run(TreeNode *root){
if (root == nullptr) return ;
if (root->left == nullptr)
{
return run(root->right) + ;
}
if (root->right == nullptr)
{
return run(root->left) + ;
}
int leftDepth = run(root->left);
int rightDepth = run(root->right);
return (leftDepth <= rightDepth) ? (leftDepth + ) : (rightDepth + );
}

1、minimum-depth-of-binary-tree的更多相关文章

  1. leetcode -day17 Path Sum I II &amp; Flatten Binary Tree to Linked List &amp; Minimum Depth of Binary Tree

    1.  Path Sum Given a binary tree and a sum, determine if the tree has a root-to-leaf path such tha ...

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

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

  4. 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree

    Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...

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

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

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

  7. LeetCode My Solution: Minimum Depth of Binary Tree

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

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

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

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

随机推荐

  1. hello2源代码解析

    String username = request.getParameter("username");/**以 String 形式返回请求参数"username" ...

  2. 数据结构与算法之PHP排序算法(堆排序)

    一.堆的定义 堆通常是一个可以被看做一棵树的数组对象,其任一非叶节点满足以下性质: 1)堆中某个节点的值总是不大于或不小于其父节点的值: 每个节点的值都大于或等于其左右子节点的值,称为大顶堆.即:ar ...

  3. .Net Core2.1 部署到IIS

    1. 发布网站,和.net framework MVC一样 2.安装WindowsHosting和.Net Core SDK 下载地址:https://www.microsoft.com/net/do ...

  4. ie 下date对象

    var t = '2014-02-26T21:18:02.497' var a = t.replace(/(\d{4})-(\d{2})-(\d{2})T(.*)?\.(.*)/, "$1/ ...

  5. vscode sass live compiler

    { "liveSassCompile.settings.formats": [{ "format": "expanded", "e ...

  6. R语言scale与unscale函数

    一.scale函数 R语言base库中自带数据标准化接口scale函数,函数介绍如下 Usage scale(x, center = TRUE, scale = TRUE) Arguments x: ...

  7. learning makefile 定义命令包

  8. layer中每次用到都要查来查去的功能

    1.关闭当前弹出层 var index = parent.layer.getFrameIndex(window.name); setTimeout(function(){parent.layer.cl ...

  9. jq demo 点击弹窗,居中,可滚动,可拖动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. itextsharp报错PdfReader not opened with owner password

    itextSharp读取Pdf时报错:PdfReader not opened with owner password 报错原因:pdf文件被用户加密了. 解决办法:在创建pdfReader实例后,加 ...