[LeetCode]题解(python):104 Maximum Depth of Binary Tree
题目来源
https://leetcode.com/problems/maximum-depth-of-binary-tree/
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.
题意分析
Input: tree
Output: int
Conditions:给定一个二叉树,返回最大深度
题目思路
递归遍历即可
AC代码(Python)
# 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 maxDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root == None:
return 0
else:
return max(self.maxDepth(root.left), self.maxDepth(root.right)) + 1
[LeetCode]题解(python):104 Maximum Depth of Binary Tree的更多相关文章
- LeetCode Javascript实现 258. Add Digits 104. Maximum Depth of Binary Tree 226. Invert Binary Tree
258. Add Digits Digit root 数根问题 /** * @param {number} num * @return {number} */ var addDigits = func ...
- LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- 104. Maximum Depth of Binary Tree(C++)
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...
- leetcode 104 Maximum Depth of Binary Tree二叉树求深度
Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...
- 【LeetCode】104. Maximum Depth of Binary Tree (2 solutions)
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the ...
- 【LeetCode】104. Maximum Depth of Binary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:BFS 方法二:DFS 参考资料 日期 题目 ...
- [LeetCode] 104. Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- LeetCode 104 Maximum Depth of Binary Tree 解题报告
题目要求 Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- (二叉树 BFS DFS) leetcode 104. Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
随机推荐
- python 代码片段
print 'dongshen' for word in ['capitalize','these','words']: print word.upper() for i in range(0,5): ...
- BZOJ1099 : [POI2007]树Drz
首先1与i交换,n与i交换,i与i+1交换的可以$O(n)$算出. 然后只需要考虑i与x交换(1<i,x<n且|i-x|>1). 设 a[i]=h[i-1] b[i]=h[i+1] ...
- BZOJ3734 : [Ontak2013]Miny
将所有炸弹按坐标排序 x<-y连边表示x爆炸了y也会爆炸 如果是DAG则直接拓扑排序+DP求出每个点出发能走到的最左端和最右端的点 有环则SCC缩点后再拓扑 用线段树优化建图的过程 边数$O(n ...
- python模块之codecs
http://blog.csdn.net/suofiya2008/article/details/5579413
- Nhibernate Case SUM
SELECT ID END) as nbRowWithValueOf2, END) as nbRowWithValueOf3 FROM Foo GROUP BY ID queryover = quer ...
- Lvs+keepalived+nginx+php的session 保持的算法
●什么是会话保持,有什么作用 会话保持是指在负载均衡器上有一种机制,在作负载均衡的同时,还保证同一用户相关连的访问请求会被分配到同一台服务器上. 会话保持有什么作用呢,举例说明一下 如果有一个用户访问 ...
- Nginx配置文件nginx.conf中文详解(总结)
PS:这篇是目前最完整的Nginx配置参数中文说明.更详细的模块参数请参考:http://wiki.nginx.org/Main #定义Nginx运行的用户和用户组 ...
- 运用正则表达式在Asp中过滤Html标签代码的四种不同方法
Function RemoveHTML(strHTML)Dim objregExp, Match, MatchesSet objRegExp = New RegexpobjRegExp.IgnoreC ...
- [ZT] 几大酒店集团美国Co-Brand信用卡比较(三)如何选择最适合你的酒店联名信用卡
原文地址: http://www.3798.com/archives/596.html 接着对我们这种不是某个酒店忠诚客户的用户选择卡片进行分析.首先要强调的是,我们比较的是信用卡项目本身,而不是酒店 ...
- 8.按要求编写Java应用程序。 (1)建立一个名叫Cat的类: 属性:姓名、毛色、年龄 行为:显示姓名、喊叫 (2)编写主类: 创建一个对象猫,姓名为“妮妮”,毛色为“灰色”,年龄为2岁,在屏幕上输 出该对象的毛色和年龄,让该对象调用显示姓名和喊叫两个方法。
package liu0917; public class Cat { String name="妮妮"; int age=2; String maose="灰色&quo ...