[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 ...
随机推荐
- 修改setInterval作用域
Hello,今天和大家分享如何修改setInterval作用域. 0.引子 最近在做一个项目的时候需要开发一个图片轮播显示的组件,在实现过程中遇到了关于setInterval作用域的问题. Slide ...
- 去掉 wap (android/ios)网页等点击后的阴影
tap后会出现一个半透明的灰色背景,(被批...),起初以为是outline作怪,加上后发现没反应,最后发现是tap后的背景高亮,要重设这个表现,则需要设置-webkit-tap-highlight- ...
- TYVJ P1030 乳草的入侵 Label:跳马问题
背景 USACO OCT09 6TH 描述 Farmer John一直努力让他的草地充满鲜美多汁的而又健康的牧草.可惜天不从人愿,他在植物大战人类中败下阵来.邪恶的乳草已经在他的农场的西北部份佔领了一 ...
- tomcat6.0安装
tomcat的安装基本是一步一步按提示来就行了: 这里填写用户名和密码,自己一定要记住啊,下面是路径的选择 然后查看安装成功与否,打开浏览器输入 然后看到下面页面就可以了
- Why Consumer Hardware Start-ups Fail
今年看到一篇文章还是很受启发. If you have the guts to start selling what you believe in, customers who share your ...
- 3. Configure the Identity Service
Controller Node: 安装认证服务: 1. sudo apt-get install keystone 2. sudo vi /etc/keystone/keystone.conf [ ...
- node系列:琐碎备忘
cmd 全局与本地路径 查看:默认 查看本地路径:npm config get cache,默认和nodejs安装目录同一目录 查看全局路径:npm config get prefix,默认c盘app ...
- 使用CodeDOM实现代码生成及动态编译
参考资料: http://www.cnblogs.com/lichdr/category/12610.html http://www.cnblogs.com/whitewolf/category/25 ...
- PHP 错误与异常 笔记与总结(4)通过 trigger_error 触发 PHP 错误
[错误抑制符@] 除了 php.ini 中 error_reporting 和 display_errors 的设置.error_reporting() 函数.ini_set() 函数 外,还可以使用 ...
- DOS实用命令/工具
winver 检查Windows版本wmimgmt.msc 打开windows管理体系结构wupdmgr windows更新程序wscript windows脚本宿主设置write 写字板w ...