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 ...
随机推荐
- [hdu1847]博弈,推理
题意:一堆石子,有n个,两个人轮流取,每次都只能取2的幂次方个数,不能取的人输 思路:首先0是必败态,2的所有幂次都是必胜态.由于选的数模3只能是1或2,恰好又都是2的幂次,0,.3都为必败态,猜想3 ...
- Nginx|构建简单的文件服务器(mac) 续-FastDFS安装(mac)|文件存储方案
目录 Nginx|构建简单的文件服务器(mac) 1 所需安装包 2 安装fastdfs-nginx-module-master 3 安装Nginx Nginx|构建简单的文件服务器(mac) 续上文 ...
- go 函数 方法 接口
概论 函数 方法 接口 概论 方法在编译时静态绑定,依托于具体的类型 接口对应的方法是在运行时动态绑定 进程内初始化顺序 初始化导入包的常量和变量(可以导出的变量)--->包的init函数,不同 ...
- java开发常见单词(复习整理)
开发中基本都能碰到,不止以下单词,后续会添加,javascript.html.mysql.spring.Linux中常用单词于此合并分类,特殊不常见不添加 访问修饰符4个--------------- ...
- jbpm4.4 timer的使用
今天学习了jbpm4 的timer使用,一直测试都不成功:配置如下: <?xml version="1.0" encoding="UTF-8"?> ...
- fastadmin后台:在表单操作项添加操作按钮并控制弹出页面的大小
1.进入对应目录:eg(public/assets/js/backend/conmpany.js) 2.在field:'operate' 中添加buttons 源码: {field: 'operate ...
- Docker之从零开始制作docker镜像
以前学习docker是直接docker pull命令直接拉取Linux中已有镜像,并创建容器,添加应用程序,但是docker镜像一开始是怎么来的呢?下面将从零开始介绍整个docker镜像的制作过程(初 ...
- percona 5.6的安装
yum 安装, 1 如果已经安装过mysql 的东西,先卸载了.yum remove mysql* 包括 /etc/my.cnf 这个东西卸载的时候不会删除. mv /etc/my.cnf /etc/ ...
- Appium自动化(9) - appium元素定位的快速入门
如果你还想从头学起Appium,可以看看这个系列的文章哦! https://www.cnblogs.com/poloyy/category/1693896.html 快速入门栗子:boss直聘 app ...
- flask之request
from flask import Flask, render_template, redirect, jsonify, send_file, request, session app = Flask ...