111、Minimum Depth of Binary Tree
2015-12-01 23:07
323 查看
题目:
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.
解题思路:
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.
解题思路:
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def minDepth(self, root): """ :type root: TreeNode :rtype: int """ def dfs(root,length): if(root==None):return length += 1 if(root.left==None and root.right==None): res.append(length) return dfs(root.left,length) dfs(root.right,length) res = [] dfs(root,0) if(res==[]):return 0 return min(res)
相关文章推荐
- TensorFlow的代码框架
- Module Zero概览
- 岛屿的个数number-of-islands
- 如何在Windows 10桌面显示我的电脑和控制面板等系统图标
- 104、Maximum Depth of Binary Tree
- runtime之Associated Objects
- Git for windows安装出错的解决办法
- 为什么你一定要有本科文凭?
- 聚簇索引概念
- 如何愉快地写代码
- VirtualBox中安装的Fedora Server与windows系统共享文件夹的方法
- Xcode快捷键汇总
- haproxy+keepalived实现高可用负载均衡
- Web APi之异常处理(Exception)以及日志记录(NLog)(十六)
- mylist
- Windows下IIS+PHP 5.2的安装与配置
- awk之变量篇
- 推荐!手把手教你使用Git
- Android第三方FloatingActionButton:伴随ListView、RecyclerView、ScrollView滚动滑入滑出
- PHP的一些小细节