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.

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) return ; min_depth = INT_MAX;
dfs(root,);
return min_depth; }
void dfs(TreeNode* node, int depth){
if(node->left)
{
dfs(node->left,depth+);
} if(node->right)
{
dfs(node->right,depth+);
} if(!node->left && !node->right)
{
if(depth < min_depth)
{
min_depth = depth;
}
}
}
private:
int min_depth;
};

111. Minimum Depth of Binary Tree (Tree; DFS)的更多相关文章

  1. [LeetCode] 111. Minimum Depth of Binary Tree_Easy tag:DFS

    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 (2 solutions)

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

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

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

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

  5. leetcode 111 Minimum Depth of Binary Tree(DFS)

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

  6. leetcode 111 minimum depth of binary tree

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

  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. 力扣算法题—111.Minimum Depth of Binary Tree

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

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

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

随机推荐

  1. 一张elixir生产环境部署的图

  2. Bootstrap组件福利篇:十二款好用的组件推荐

    阅读目录 一.时间组件 1.效果展示 2.源码说明 3.代码示例 二.自增器组件 1.效果展示 2.源码说明 3.代码示例 三.加载效果 一.实用型 二.炫酷型 四.流程图小插件 1.效果展示 2.源 ...

  3. golang里面检测对象是否实现了接口的方法

    写法有点怪异,记一下吧 _, implemented := this.delegate.(IGenTcpServerDelegate) if implemented { this.delegate.G ...

  4. NumberUtils、ArrayUtils和RandomUtils工具类用法

    一.NumberUtils工具类 /*1.NumberUtils.isNumber():判断字符串是否是数字*/ NumberUtils.isNumber("5.96");//结果 ...

  5. CSS 基本知识梳理-续

    CSS 基本知识 1.CSS 简介 CSS 指层叠样式表 (Cascading Style Sheets),是一种用来表现 HTML 文档样式的语言,样式定义如何显示 HTML 元素,是能够真正做到网 ...

  6. 解决Vmware workstation上不能安装Hyper-V的问题

    从今天开始,博主正式开始学习微软相关的知识了.众所周知,微软的虚拟化技术Hyper-V现在也很火.可是博主也没有一台服务器来装Hyper-V.于是想到在自己的PC上先装一个Vmware worksta ...

  7. 【CVE】CVE-2018-4304 Apple多个操作系统函数拒绝服务漏洞

    TextImpact: Processing a maliciously crafted text file may lead to adenial of serviceDescription: A ...

  8. linux tcp调优

    Linux TCP Performance Tuning News Linux Performance Tuning Recommended Books Recommended Links Linux ...

  9. sql developer Oracle 数据库 用户对象下表及表结构的导入导出

    Oracle数据库表数据及结构的导入导出   导出的主机与即将导入到的目标主机的tablespace 及用户名需一直!!!!!

  10. HTTP接口开发专题四(接收http接口发送过来的请求)

    前面讲了调用http接口的操作,这篇讲下接收http接口的操作.(以Spring MVC为例) 1)如果发送过来的内容类型是application/x-www-form-urlencoded ,则按照 ...