111. Minimum Depth of Binary Tree (Tree; DFS)
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)的更多相关文章
- [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 ...
- 【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 ...
- [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)
[Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有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 ...
- 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 ...
- leetcode 111 minimum depth of binary tree
problem description: Given a binary tree, find its minimum depth. The minimum depth is the number of ...
- [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 ...
- 力扣算法题—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 ...
- 【LeetCode】111. Minimum Depth of Binary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 [LeetCode] 题目地址 ...
随机推荐
- ballerina 学习七 object 创建&& 初始化
在 ballerina 总中object 是一个包含public private 类型字段同时包含函数,需要开发人员进行自定义类型以及行为 说白了,就是类似面向对象的class 基本使用 代码 imp ...
- k8s helm 私服chartmuseum minio s3 存储配置
1. 安装minio 使用docker 安装 参考项目 https://github.com/rongfengliang/mino-thumbor-openresty 备注: 因为是一个集成项目可能会 ...
- 让nodejs 支持 es6 import
备注: 尽管nodejs 新版本已经支持es6 的好多特性了,但是还是有部分不支持,为了使用,实际上我们有一个 比较强大工具 bable,下面介绍几个比较简单的用法. 1. bable-cli ...
- bzoj 2597 [Wc2007]剪刀石头布——费用流
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2597 三个人之间的关系,除了“剪刀石头布”,就是有一个人赢了2局:所以考虑算补集,则每个人对 ...
- elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)
分给线一下内容为理解错误内容,实际允许建立父子分档,只是类型改成来 join 官方demo: join datatypeedit The join datatype is a special fiel ...
- SQL中利用脚本恢复数据库
SQL中利用脚本恢复数据库 编写人:CC阿爸 2014-6-15 在日常SQL数据库的操作中,如何恢复数据库 use master drop database SCS1 RESTORE DATAB ...
- 使用sigaction来取代signal作为信号处理器函数
早期ISO C提供了像这样的函数来支持自定义信号处理 typedef void (*sighandler)(int); sighandler signal(sighandler func); 但是由于 ...
- FPGA常用设计思想与基本模块划分
常用设计思想与技巧 (1)乒乓操作; (2)串并转换; (3)流水线操作; (4)异步时钟域数据同步.是指如何在两个时钟不同步的数据域之间可靠地进行数据交换的问题.数据时钟域不同步主要有两种情况: ① ...
- android 手机UDP 接受不到数据
一.有的手机不能直接接收UDP包,可能是手机厂商在定制Rom的时候把这个功能给关掉了. 1.可先在oncreate()方法里面实例化一个WifiManager.MulticastLock 对象lock ...
- clientHeight , scrollHeight , offsetHeight之间的区别及兼容方案
clientHeight , scrollHeight , offsetHeight相信每个人都用过,可是每次用都要查一下到底哪个是文档大小哪个是视口大小,还有头疼的兼容问题. 先来官方的了解一下这三 ...