Leetcode-标签为Tree 111. Minimum Depth of Binary Tree
来源:互联网 发布:2200万淘宝买家资料 编辑:程序博客网 时间:2024/06/18 12:49
原题
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.
题目分析
求最小深度。注意是从根到叶子的最小距离
代码实现
public class Solution { public int MinDepth(TreeNode root) { if(root==null) return 0; if(isLeaf(root)) return 1; if(root.left==null) return 1 + MinDepth(root.right); if(root.right ==null) return 1 + MinDepth(root.left); return Math.Min(MinDepth(root.left),MinDepth(root.right))+1; } private bool isLeaf(TreeNode node) { return node.left==null && node.right==null; }}
2 0
- Leetcode-标签为Tree 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
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 【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
- LeetCode 111.Minimum Depth of Binary Tree
- Leetcode 111. Minimum Depth of Binary Tree
- [leetcode]111.Minimum Depth of Binary Tree
- 111.[Leetcode]Minimum Depth of Binary Tree
- LeetCode 111. Minimum Depth of Binary Tree
- 【leetcode】111. Minimum Depth of Binary Tree
- KVO实现自定义文件复制进度展示
- LeetCode 147 Insertion Sort List(链表)
- 16国赛1题
- Md5实现算法源码
- 基于DEM提取经纬度
- Leetcode-标签为Tree 111. Minimum Depth of Binary Tree
- Maven tomcat7-maven-plugin 部署Maven Web 项目
- Android自定义控件系列之应用篇——圆形进度条
- JQuery日期插件datepicker的使用
- 机器视觉光源知识总结(二)
- C++struct结构
- 调整数组顺序使奇数位于偶数前面
- F题 Turing equation
- soc时钟系统