LeetCode#111 Minimum Depth of Binary Tree
2015-07-21 20:19
597 查看
Problem Definition:
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.
Solution:
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.
Solution:
def minDepth( root): if root==None: return 0 if root.left==None or root.right==None: return max(self.minDepth(root.left), self.minDepth(root.right))+1 return min(self.minDepth(root.left), self.minDepth(root.right))+1
相关文章推荐
- 小波说雨燕 第三季 构建 swift UI 之 UI组件集-视图集(六)Picker View视图 学习笔记
- 【Treap】poj1442 Black Box
- 修改UIImage大小
- select实现输入模糊匹配与选择双重功能
- FirstAFNetWorking
- HDU 2818 - Building Block
- 活动目录(一)创建根域
- Tomcat服务器讲解
- lx-0721-1008不要62
- UIButton的一些设置
- linux ln 命令使用参数详解(ln -s 软链接)
- android 之 Intent 传递数据大小有限的问题
- android http中请求访问添加 cookie
- LeetCode#112 Path Sum
- 手机测试项目时报INSTALL_FAILED_INSUFFICIENT_STORAGE
- A Common Data Access Architecture
- 字符串替换
- 树状数组的初次邂逅
- 堆和栈的区别(转过无数次的文章)
- lx-0721-1004汉字统计