minimum-depth-of-binary-tree leetcode C++
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.
C++
class Solution {
public:
//run:12ms memory:884k
int run(TreeNode *root) {
if (NULL == root) return 0;
if (NULL == root->left && NULL == root->right) return 1;
if (NULL == root->left) return run(root->right) + 1;
else if(root->right == NULL) return run(root->left) + 1;
else return min(run(root->left),run(root->right)) + 1;
}
};
minimum-depth-of-binary-tree leetcode C++的更多相关文章
- Minimum Depth of Binary Tree ——LeetCode
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Minimum Depth of Binary Tree [LeetCode]
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Minimum Depth of Binary Tree leetcode java
题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...
- 【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][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练习题】Minimum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode My Solution: Minimum Depth of Binary Tree
Minimum Depth of Binary Tree Total Accepted: 24760 Total Submissions: 83665My Submissions Given a bi ...
随机推荐
- Docker安装mysql镜像并进行主从配置
Docker安装mysql镜像并进行主从配置 1.下载需要的mysql版本镜像 docker pull mysql:5.6 2.启动mysql服务实例(基本启动) #启动主mysql docker r ...
- Xshell和Xftp - 下载安装
简介 Xshell 实际工作运用:连接Linux Xftp 实际工作运用:传输文件到Linux系统 下载安装 三连后评论区留言私发,此贴长期有效!!!
- 华为云计算IE面试笔记-桌面云用户登录连接流程及故障处理?
1-10:桌面与系统验证成功 http协议 11-19:桌面list(VM列表)获取,选择 http协议 20-30: ...
- 解决Windows 游戏 错误代码 1170000
安装"Xbox标识提供程序" 下载地址:https://www.microsoft.com/store/apps/9wzdncrd1hkw
- YbtOJ#482-爬上山顶【凸壳,链表】
正题 题目链接:https://www.ybtoj.com.cn/contest/116/problem/2 题目大意 \(n\)个点,\(x\)坐标递增,第\(i\)个点向第\(j\)个点连边. 开 ...
- 初探计算机网络之CPU和内存
CPU CPU是一块超大规模的集成电路板,是计算机的核心部件,承载着计算机的主要运算和控制功能,是计算机的最终解释模块和执行模块.总之,用一句话概括就是,CPU是由控制器和运算器组成的,而内部寄存 ...
- 10.6 Nginx 高并发连接
Nginx 高并发连接 什么是IO,输入输出 Web服务器IO的整个详细过程 (1)客户发起请求到服务器网卡: (2)服务器网卡接受到请求后转交给内核 ...
- 使用node-gyp编写简单的node原生模块
通过样例,让我们了解如何编写一个node的原生模块.当然,这篇文章还有一个目的,是为了方便以后编写关于node-gyp的文章,搭建初始环境. 基于node-addon-api 基于node-addon ...
- SpringCloud微服务实战——搭建企业级开发框架(四):集成SpringCloud+SpringBoot
1.在GitEgg工程的根目录,最上级父pom.xml文件中引入需要依赖的库及Maven插件,设置编码方式: <!--?xml version="1.0" encoding= ...
- 如何获取ISO8601定义的Work Week
工作中遇到一个需求,需要在打印标签的时候打印生产当天的工作周.工作周按照ISO-8601定义的标准计算.找到两种方案. Excel函数 C#代码 Excel函数 非常简单,调用一个Excel自带函数就 ...