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 ...
随机推荐
- 基于CentOS搭建基于 ZIPKIN 的数据追踪系统
系统要求:CentOS 7.2 64 位操作系统 配置 Java 环境 安装 JDK Zipkin 使用 Java8 -openjdk* -y 安装完成后,查看是否安装成功: java -versio ...
- javascript中的数据结构
Javascript中的关键字 abstract continue finally instanceof private this boolean ...
- 解决“错误为Lc.exe已退出,代码为-1”
今天做项目的时候突然出现编译不通过,错误为Lc.exe已退出,代码为-1.网查了一下,原因是项目中使用了第三方组件(Developer Express v2011)造成的,分享如下:这个第三方组件是个 ...
- 使用RStudio远程连接MySQL
环境: 远程机: linux + Mysql 本地机: Windows + RStudio 问题: 1. 远程机为内网机器,需要跳板机连接,没有公网ip,无法连接 解决方案:修改跳板机的iptable ...
- Kubernetes的ConfigMap解析
ConfigMap功能在Kubernetes1.2版本的时候就有了,许多应用程序会从配置文件.命令行参数或环境变量中读取配置信息.这些配置信息需要与docker image解耦,你总不能每修改一个配置 ...
- Atitit 数据库view视图使用推荐规范与最佳实践与方法
Atitit 数据库view视图使用推荐规范与最佳实践与方法 1. 视图的优点:1 1.1. **提升可读性 定制用户数据,聚焦特定的数据1 1.2. 使用视图,可以简化数据操作. 1 ...
- C++ 类占用空间计算方式
1.一个类占用的空间主要是属性占用空间,而成员函数一般不占用空间,但是虚函数占用空间,需要说明的是,无论多少个虚函数,只要占用4个字节即可,也就是索引指向一个虚拟表的首位置.另外需要说明的是占用空间都 ...
- github团队协作
1.打开项目 2.将成员添加到项目成员内 3.创建分支 4.提交修改到远程仓库 5.发起讨论Pull requests 6.以讨论结果修改后,合并到master
- Android Launcher分析和修改10——HotSeat深入进阶
前面已经写过Hotseat分析的文章,主要是讲解如何在Launcher里面配置以及修改Hotseat的参数.今天主要是讲解一下如何在Hotseat里面的Item显示名称.这个小问题昨天折腾了半天,最后 ...
- python初级 2 字符串格式化
一.回顾 上次我们讲解的数据类型,有int,float,str,bool,NoneType五种 前两种和后两种都比较简单,str较为复杂 二.字符串格式化的使用场景: 有一种字符串, xxx 的内容都 ...