[leetcode] 111.Mininum Depth of Binary Tree (Easy)
原题
寻找二叉树最短深度
这里用了dfs,beat 100%,4ms
class Solution
{
public:
int minDepth(TreeNode *root, int minNum = 0)
{
if (root == NULL)
{
return minNum == 0 ? minNum : 999999;
}
if (root->left == NULL && root->right == NULL)
return minNum + 1;
return min(minDepth(root->left, minNum + 1),
minDepth(root->right, minNum + 1));
}
};
[leetcode] 111.Mininum Depth of Binary Tree (Easy)的更多相关文章
- [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 ☆(二叉树的最小深度)
[Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...
- Leetcode 111 Minimum Depth of Binary Tree 二叉树
找出最短的从叶子到根的路径长 可以回忆Maximum Depth of Binary Tree的写法,只不过在!root,我把它改成了10000000,还有max函数改成了min函数,最后的值如果是1 ...
- 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
problem description: Given a binary tree, find its minimum depth. The minimum depth is the number of ...
- 【leetcode】Minimum Depth of Binary Tree (easy)
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 ----- java
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Java [Leetcode 111]Minimum Depth of Binary Tree
题目描述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...
- (二叉树 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 ...
随机推荐
- 前端工程师应该都了解的16个最受欢迎的CSS框架
摘要: 今天给大家分享16个最受欢迎的CSS框架.这些是根据笔者的爱好以及相关查阅规整出来的.可能还有一些更棒的或者您更喜欢的没有列举出来.如果有,欢迎留言! Pure : CSS Framework ...
- 网易Lofter
作为老网虫,对网易的感情是很深的.当我知道Lofter这个东西后,曾经很兴奋要好好打理自己的博客,然而兴奋很快过了.因为Lofter无时无刻不在刷存在感.无限空间加无限图片流量,国内的服务无法做的更好 ...
- Qt之QGraphicsEffect阴影、模糊效果
Qt之QGraphicsEffect阴影.模糊效果 Qt之QGraphicsEffect阴影模糊效果 效果图 阴影和模糊效果 正常效果 代码 customshadoweffecth customsha ...
- springmvc拦截请求
springmvc.xml <!--拦截请求 --> <mvc:interceptors> <mvc:interceptor> <!-- 要拦截的请求类型 / ...
- nice-validator表单验证插件的简单使用
前言 前端表单校验是过滤无效数据.假数据.有毒数据的第一步,是数据安全的第一道关卡,虽然我们不能100%相信客户端提交的数据(真正的校验还得在服务端进行),但设置前端表单校验也是至关重要的,自己写逻辑 ...
- python+Django 下JWT的使用
figure:first-child { margin-top: -20px; } #write ol, #write ul { position: relative; } img { max-wid ...
- .Net将集合M内非空参数值的参数按照参数名ASCII码从小到大排序(字典序),并使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串stringA
前言: 前段时间因为项目进度比较繁重所以一直都没有时间更新博客,内心深深的负重感,没有履行年初立下的flag.不过这个月会把上个月没有完成的任务补上来,咱们可不是喜欢拖欠任务的攻城狮.哈哈,废话不多说 ...
- Go语言学习——channel的死锁其实没那么复杂
1 为什么会有信道 协程(goroutine)算是Go的一大新特性,也正是这个大杀器让Go为很多路人驻足欣赏,让信徒们为之欢呼津津乐道. 协程的使用也很简单,在Go中使用关键字“go“后面跟上要执行的 ...
- 简单的 自动生成 二维码 PHP 方法
方法一:<style type="text/css">.eweima{ width:200px; height:200px; margin:auto;}</ ...
- spring源码深度解析— IOC 之 属性填充
doCreateBean() 主要用于完成 bean 的创建和初始化工作,我们可以将其分为四个过程: createBeanInstance() 实例化 bean populateBean() 属性填充 ...