[leetcode]111. Minimum Depth of Binary Tree@Java解题报告
来源:互联网 发布:耳机煲机的音乐知乎 编辑:程序博客网 时间:2024/06/05 06:26
https://leetcode.com/problems/minimum-depth-of-binary-tree/description/
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.
package go.jacob.day807;/** * 111. Minimum Depth of Binary Tree * @author Jacob * */public class Demo5 {/* * 方法一 */public int minDepth(TreeNode root) { if(root == null) return 0; int left = minDepth(root.left); int right = minDepth(root.right); return (left == 0 || right == 0) ? left + right + 1: Math.min(left,right) + 1; }/* * 方法二 */public int minDepth_1(TreeNode root) {if(root==null)return 0;if(root.left==null)return 1+minDepth(root.right);if(root.right==null)return 1+minDepth(root.left);return 1+Math.min(minDepth(root.left), minDepth(root.right));}}
阅读全文
0 0
- [leetcode]111. Minimum Depth of Binary Tree@Java解题报告
- [leetcode] 111. Minimum Depth of Binary Tree 解题报告
- LeetCode解题报告 111. Minimum Depth of Binary Tree [easy]
- [Leetcode] 111. Minimum Depth of Binary Tree 解题报告
- 【LeetCode】Minimum Depth of Binary Tree 解题报告
- LeetCode(111) Minimum Depth of Binary Tree解题报告
- [leetcode]104. Maximum Depth of Binary Tree@Java解题报告
- [Leetcode] Minimum Depth of Binary Tree (Java)
- [LeetCode][Java] Minimum Depth of Binary Tree
- LeetCode|Minimum Depth of Binary Tree-java
- leetcode:Minimum Depth of Binary Tree 【Java】
- LeetCode 111. Minimum Depth of Binary Tree
- [LeetCode]111.Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- [Leetcode] 111. Minimum Depth of Binary Tree
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 【LeetCode】111. Minimum Depth of Binary Tree
- JavaWeb学习篇之----Session&&Cookie
- 优化网站性能必备的6种架构方案,你知道吗?
- 异常处理
- 滤波的实现
- mysql登录不上的问题
- [leetcode]111. Minimum Depth of Binary Tree@Java解题报告
- 二叉树的遍历
- tomcat 连接多个数据源
- 步进电机应用过程中注意事项
- hadoop spark环境搭建及idea scala maven集成开发spark任务
- Mac/OSX root/sudo Operation not permitted
- xmake新增智能代码扫描编译模式
- 一份关于webpack2和模块打包的新手指南
- js函数调用时,加括号与不加括号的区别