LeetCode 112 Minimum Depth of Binary Tree
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.
Note: A leaf is a node with no children.
Example:
Given binary tree [3,9,20,null,null,15,7]
,
return its minimum depth = 2.
求最小的深度,二叉树,这道题目我认为数据是有问题的,所以有176个踩,
c++
class Solution {
public:
int minDepth(TreeNode* root) {
if(root==NULL) return ;
int lmin =;
int rmin =;
if(root->left!=NULL)
lmin = minDepth(root->left);
if(root->right!=NULL)
rmin = minDepth(root->right);
if(lmin==)
return rmin+;
if(rmin==)
return lmin+;
return min(lmin,rmin)+; }
};
LeetCode 112 Minimum Depth of Binary Tree的更多相关文章
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)
[Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...
- LeetCode OJ Minimum Depth of Binary Tree 递归求解
题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 111. Minimum Depth of Binary T ...
- [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][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 ...
- 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
题目简述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...
随机推荐
- 解决Ubuntu Chrome浏览器很卡不响应的问题
1. 设定字体,使用Ubuntu Tweak Tool把系统字体设定为默认字体,而不是文泉驿字体: 2. 使用ADBLock Plus把垃圾的广告过滤掉,不然网页上很多Flash就会导致网页非常的卡顿 ...
- 转 sshfs把远程主机的文件系统映射到本地的目录中
windows之外的世界比想像中要大得多呢,几乎天天都在用ssh,却到今天才知道有sshfs这个好东西,前几天还在为ZendStudio可以远程编辑文件欣喜,惭愧啊,终于有比vi scp://host ...
- 【转载】js关闭当前页面(窗口)的几种方式总结
1. 不带任何提示关闭窗口的js代码 复制代码代码如下: <a href="javascript:window.opener=null;window.open('','_self'); ...
- python gb2312 转换为 utf-8
url = "" headers = { "Host":"www.chinanews.com", "User-Agent" ...
- C# 版本的24点实现
C# 版本的24点实现. 已经实现基本功能,可以正确的算 3, 3, 8, 8 这类组合. 稍加修改就可以支持任意数目的操作数和操作符组合形成的四则运算表达式,不限于24点. 代码还比较简单粗糙,晚一 ...
- [DIOCP视频]-DIOCPFileServer视频
本次视频简单讲解了DiocpFileServer + 客户端使用接口方式,通信方面可以方便的在DiocpBlockTcpClient和IdTcpClient组件之间切换. + 添加单独的EXE客户端( ...
- Android——RecycleView
RecycleView设置点击事件 http://blog.csdn.net/guxiao1201/article/details/40423361
- Nginx 1.9+PHP5.6 环境搭建
PHP5. 下载安装包 #wget http://mirrors.sohu.com/php/php-5.6.2.tar.gz #tar -zxf php- 安装php依赖的包 #yum inst ...
- CentOS 添加 Oracle YUM 源
最新文章:Virson's Blog 文章来自:Oracle 官方 YUM 源 Introduction The Oracle public yum server offers a free and ...
- SAP HANA S4 FI TABLE表结构
一.统一日记账的表 1)一个行项目表,存储所有应用的全部明细–迅速获得洞察力和扩展能力; 2)次级成本要素也变成了总账科目,统一入口维护和管理; 3)数据只需存储一次在一张表,不需要再做月末对账,如A ...