Java实现LeetCode 111. Minimum Depth of Binary Tree
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int minDepth(TreeNode root) {
if(root == null){
return 0;
}
if((root.left == null) && (root.right == null)){
return 1;
}
int min_depth = Integer.MAX_VALUE;
if(root.left != null){
min_depth = Math.min(minDepth(root.left),min_depth);
}
if(root.right != null){
min_depth = Math.min(minDepth(root.right),min_depth);
}
return min_depth+1;
}
}
Java实现LeetCode 111. Minimum Depth of Binary Tree的更多相关文章
- Java for 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 二叉树的最小深度
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 ☆(二叉树的最小深度)
[Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...
- Leetcode 111 Minimum Depth of Binary Tree 二叉树
找出最短的从叶子到根的路径长 可以回忆Maximum Depth of Binary Tree的写法,只不过在!root,我把它改成了10000000,还有max函数改成了min函数,最后的值如果是1 ...
- leetcode 111 Minimum Depth of Binary Tree ----- java
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shor ...
- Java [Leetcode 111]Minimum Depth of Binary Tree
题目描述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...
- 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 ...
- (二叉树 BFS DFS) 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 ...
随机推荐
- linux输入输出、重定向、管道
本篇讲述linux系统的输入输出.管道和重定向. 1. liunx的输入输出 一个linux系统要想发挥作用,就要有输入输出,这样才可以与外界交互. 类型 设备文件名 文件描述符 设备名称 说明 备注 ...
- 腾讯面试居然跟我扯了半小时的CountDownLatch
一个长头发.穿着清爽的小姐姐,拿着一个崭新的Mac笔记本向我走来,看着来势汹汹,我心想着肯定是技术大佬吧!但是我也是一个才华横溢的人,稳住我们能赢. 面试官:看你简历上有写熟悉并发编程,CountDo ...
- AFNetworking 3.0 使用详解 和 源码解析实现原理
AFN原理&& AFN如何使用RunLoop来实现的: 让你介绍一下AFN源码的理解,首先要说说封装里面主要做了那些重要的事情,有那些重要的类(XY题) 一.AFN的实现步骤: NSS ...
- android 数据库是否该关闭
关于android多线程数据读写请看博客: android 多线程数据库读写 常常纠结于获取了SQLiteDatabase每次操作完是否要关闭的问题,每次关闭又怕影响性能,这里记录下SQLiteOpe ...
- Java openrasp学习记录(一)
前言: 最近一直在做学校实验室安排的项目,太惨了,没多少时间学习新知识,不过rasp还是要挤挤时间学的,先从小例子的分析开始,了解rasp的基本设计思路,后面详细阅读openrasp的源码进行学习!欢 ...
- django安装及其他模块导入
django安装 python项目第三方模块配置 pip3 list------查看当前pip安装的第三方模块
- xampp-apache配置
我安装的软件是xampp-win32-1.8.2-0-VC9-installer 需要配置的文件有 httpd.conf httpd-default.conf httpd-info.conf http ...
- hdu6092 01背包
Rikka with Subset Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- Codeblocks运行按钮变灰,卡程序编译
实际上,当我们点击绿色运行按钮运行之后,.exe文件会开始运行,当我们点击红色调试按钮之后,会开始调试. 因此当我们在运行卡住之后,点击红色调试按钮,实际上并没有真正的结束程序,只是将窗口隐藏起来,我 ...
- PHP SQL预处理
php预处理查询 $query='insert into p1(info) values(?)'; $query2='select info from p1 where id=?'; $country ...