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 ...
随机推荐
- scrum项目冲刺_day04总结
摘要:今日完成任务. 1.图像识别已优化 2.语音识别正在进行 3.搜索功能 正在进行 总任务: 一.appUI页面(已完成) 二.首页功能: 1.图像识别功能(已完成) 2.语音识别功能 3.垃圾搜 ...
- 01_初识C语言
第一章 - 初识C语言 基本了解C语言的基础知识,对C语言有一个大概的认识. 每个知识点就是简单认识,不做详细讲解. 1. 什么是C语言? C语言是一门通用计算机编程语言,广泛应用于底层开发.C语言的 ...
- springboot:@ConditionalOnProperty根据不同时机注入不同实现的bean
一.引言 在开发中经常会碰到这样的情形,一个接口会有不同的实现,但在开发中都是基于接口的注入,那么怎么根据不同的需求注入不同的类型就是一个值得考虑的问题.在注入属性时常用的两个注解是@Autowire ...
- python IO流操作
python IO流操作 学习完本篇,你将会独立完成 实现操作系统中文件及文件目录的拷贝功能. 将目标图片拷贝到指定的目录中 实现一个自动阅卷程序, Right.txt保存正确答案,xx(学生姓名). ...
- Jmeter系列(8)- 参数化:JSON提取器、全局参数化、CSV文件导入
JSON提取器 同一个响应结果需要提取多个参数进行参数化,下方输入项用分号(;)进行间隔.请求引用时${变量名} 全局参数化 此处全局参数化用的是用户自定义的变量 CSV文件导入
- Shell系列(19)- 正则表达式
正则表达式与通配符 正则表达式用来在文件中匹配符合条件的字符串,正则是包含匹配.grep,awk,sed等命令可以支持正则表达式. 通配符用来匹配符号条件的文件名,通配符是完全匹配.ls,find,c ...
- GUI自动化测试遇到的问题
学习接口自动化测试框架或工具,UI自动化测试框架或工具,有时会觉得知识似乎比较零散,死记硬背不是一个好方法.一个学习的思路是思考使用这些框架或工具的时候,可能会遇到什么问题,遇到这些问题可以通过什么方 ...
- 鸿蒙内核源码分析(信号消费篇) | 谁让CPU连续四次换栈运行 | 百篇博客分析OpenHarmony源码 | v49.04
百篇博客系列篇.本篇为: v49.xx 鸿蒙内核源码分析(信号消费篇) | 谁让CPU连续四次换栈运行 | 51.c.h .o 进程管理相关篇为: v02.xx 鸿蒙内核源码分析(进程管理篇) | 谁 ...
- P5644-[PKUWC2018]猎人杀【NTT,分治】
正题 题目链接:https://www.luogu.com.cn/problem/P5644 题目大意 \(n\)个人,每个人被选中的权重是\(a_i\).每次按照权重选择一个没有死掉的人杀死,求第\ ...
- Redis之品鉴之旅(七)
分布式锁 1)阻塞锁: 尝试在redis中创建一个字符串结构缓存,方法传入的key,value为锁的过期时间timeout的时间戳. 若redis中没有这个key,则创建成功(即抢到锁),然后立即返回 ...