Minimum Depth of Binary Tree [LeetCode]
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.
Summary: BFS or DFS with recursion.
int minDepth(TreeNode *root) {
if(root == NULL)
return ;
if(root->left == NULL && root->right == NULL)
return ;
if(root->right == NULL)
return minDepth(root->left) + ;
if(root->left == NULL)
return minDepth(root->right) + ;
return min(minDepth(root->left), minDepth(root->right)) + ;
}
Minimum Depth of Binary Tree [LeetCode]的更多相关文章
- 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 ...
随机推荐
- java实现ftp文件的上传与下载
最近在做ftp文件的上传与下载,基于此,整理了一下资料.本来想采用java自带的方法,可是看了一下jdk1.6与1.7的实现方法有点区别,于是采用了Apache下的框架实现的... 1.首先引用3个包 ...
- windows programming can't find windows.h
在用控制台编译c++程序的时候,可能会遇到找不到windows.h的情况.这是因为我们在使用cl命令的时候,并没有配置好环境变量. 所以我们在运行cl命令之前,我们可以运行C:\Program Fil ...
- Bash:-:-定义空变量作为输出结合换行符\n和column输出
RET="" declare -a HOST=() declare -a ALL_SVR=() declare -a FREESVR=() ;i<${#_ALL_AGENT_ ...
- IOS textView获取光标定位,以及选中
当textview成为第一响应者的时候就会调用一个协议方法 - (void)textViewDidChangeSelection:(UITextView *)textView; 在这个协议方法中可以实 ...
- webpack react基础配置一
简单介绍webpack react基本配置,入门型: 环境配置: 依赖nodejs,官网下载最新版的nodejs:nodejs.org/en 安装完nodejs npm便自动集成了,通过npm安装其 ...
- bootstrop框架
bootstrop基本的基础了解有如上图.. 下载源码 从GitHub可以直接下载到Bootstrap最新版本的LESS和JavaScript源码. Clone or fork via GitHub ...
- 学生信息管理系统(cocos2d引擎)——数据结构课程设计
老师手把手教了两天半,看了一下模式,加了几个功能就大功告成了!!! 给我的感想就是全都是指针! 添加图片精灵: CCSprite* spBG = CCSprite::create("&qu ...
- 系统服务监视、系统服务守护 ServiceMonitor
源码及版权来自易语言论坛邓学彬,本人只是稍微修改了一下. 下载链接: https://pan.baidu.com/s/1i4Aja4l 密码: 8fuv
- uwsgi出现invalid request block size: 21573 (max 4096)...skip解决办法
buffer-size uwsgi内部解析的数据包大小,默认4k. 如果准备接收大请求,你可以增长到64k. 允许uwsgi接收到32k,更大的会被丢弃. xweb.ini [uwsgi]socket ...
- 【leetcode❤python】 303. Range Sum Query - Immutable
#-*- coding: UTF-8 -*- #Tags:dynamic programming,sumRange(i,j)=sum(j)-sum(i-1)class NumArray(object) ...