Minimum Depth of Binary Tree - LeetCode
来源:互联网 发布:好用的拼图软件 编辑:程序博客网 时间:2024/05/17 04:46
Minimum Depth of Binary Tree - LeetCode
题目:
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.
分析:
感觉应该是有关树的题目都可以递归解决。找到最小路径用min函数。
代码:
class Solution: # @param root, a tree node # @return an integer def minDepth(self, root): if not root: return 0 if not root.right: return self.minDepth(root.left)+1 elif not root.left: return self.minDepth(root.right)+1 else: return min(self.minDepth(root.right),self.minDepth(root.left))+1
0 0
- LeetCode: Minimum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- LeetCode : Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- 【leetcode】Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree
- [LeetCode]Minimum Depth of Binary Tree
- [Leetcode]Minimum Depth of Binary Tree
- [leetcode]Minimum Depth of Binary Tree
- Leetcode: Minimum Depth of Binary Tree
- LeetCode-Minimum Depth of Binary Tree
- [leetcode] Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- 【Leetcode】Minimum Depth of Binary Tree
- LeetCode | Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- SVN版本控制器的服务器安装端-----> VisualSvn Server包括Subversion、Apache和用户及权限管理
- 新浪微博sso package or sign error错误
- linux命令修改IP信息
- 雷军的极致
- linux静态库与动态库的区别与使用
- Minimum Depth of Binary Tree - LeetCode
- LeetCode 154. Find Minimum in Rotated Sorted Array II
- Manacher's ALGORITHM
- BZOJ 2146 Construct 计算几何
- 【Linux是什么】 Linux的特色
- Piwik统计添加用户ID编号
- 【设计模式】Iterator迭代器设计模式(容器和容器的遍历)
- 失恋阵线同盟
- hihocoder-1032