leetcode 111. Minimum Depth of Binary Tree
来源:互联网 发布:爱奇艺点击率换算法 编辑:程序博客网 时间:2024/04/29 12:48
题目:
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.
求二叉树的最小深度,二叉树的最小深度为根节点到最近叶子节点的距离。
与二叉树的最大深度不同,因为二叉树的最小深度必须是根结点到叶子结点的距离,不能单纯的比较左右子树的递归结果返回较小值,因为对于有单个孩子为空的节点,为空的孩子会返回0,但这个节点并非叶子节点,故返回的结果是错误的。
因此,当发现当前处理的节点有单个孩子是空时,返回一个极大值Integer.MAX_VALUE,防止其干扰结果。
代码AC:
0 0
- 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
- LeetCode 111. Minimum Depth of Binary Tree
- 已知圆的半径和弧长求弧的终点坐标(360春招跑步编程题)
- 基站定位LAC,CID转经纬度
- (JVM1)Java内存区域与内存溢出异常之二
- 基于OGG的Oracle与Hadoop集群准实时同步介绍
- WinRAR去广告心得
- leetcode 111. Minimum Depth of Binary Tree
- linux 批量ping检测
- linux目录权限修改(以及umask用法)
- 排序总结----希尔排序
- Ubuntu(Linux)下Matlab R2016b重编译并配置vlfeat0.9.20
- TortoiseSVN 连接资源库时 opration in progerss
- 使用Notepad2替代系统笔记本
- 资料验证及回呼
- CRF(condition random field)