104. Maximum Depth of Binary Tree
2015-12-23 11:20
316 查看
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
class Solution(object):
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
def get_depth(r):
if r==None:
return 0
else:
a=get_depth(r.left)
b=get_depth(r.right)
if a>b:
b=a
return b+1
return get_depth(root)
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
class Solution(object):
def maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
def get_depth(r):
if r==None:
return 0
else:
a=get_depth(r.left)
b=get_depth(r.right)
if a>b:
b=a
return b+1
return get_depth(root)
相关文章推荐
- Android:使用android-support-design实现MD风格对话框
- Spring入门Blog[七、Spring Aop的理解和简单实现]
- TableView如何刷新指定的cell 或section和滚动到制定位置
- Objective C类方法load和initialize的区别
- Bug之解决Xcode 7编译错误:* does not contain bitcode.
- Netty实现原理浅析
- Android小技巧:动态设置布局属性addRule
- ubuntu 安装 tomcat7
- PCL—低层次视觉—关键点检测(iss&Trajkovic)
- [Web前端]梳理-DOM.16. event对象
- 程序运行前退出前动画
- 自己动手整合ssh
- redis主从配置及主从切换
- 微信SDK导入到Xcode中编译错误
- 搜索栏UISearchBar和UISearchController
- DialogFragment实现自定义进度条
- linux 命令之 getfacl
- jdk+tomcat
- javascript数据类型(一)
- 项目中phpexcel的基本用法