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 longest path from the root node down to the farthest leaf node.
Note: A leaf is a node with no children.
题目分析及思路
给定一棵二叉树,要求返回它的最大深度。最大深度是指在从根结点到最远叶结点的路径上的结点数。可以使用递归的方法,条件为结点为空。
python代码
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def maxDepth(self, root: TreeNode) -> int:
if not root:
return 0
return 1+max(self.maxDepth(root.left), self.maxDepth(root.right))
LeetCode 104 Maximum Depth of Binary Tree 解题报告的更多相关文章
- 【LeetCode】104. Maximum Depth of Binary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:BFS 方法二:DFS 参考资料 日期 题目 ...
- LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告
104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...
- 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 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- (二叉树 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 long ...
- Java [Leetcode 104]Maximum Depth of Binary Tree
题目描述: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along th ...
- 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 ...
- Java for 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 ...
随机推荐
- idea git 使用
第一部 测试 本地git 是否已经成功安装 centos 7 发行版默认已经安装 第二部: 测试 github 连接是否成功,需要输入用户密码 第三部:创建git项目管理两种方式 1. 菜单 VC ...
- Jenkins这种构建工具,一般都是内部使用,所以外部基本上不能访问
类似于Jenkins这种构建工具,一般都是内部使用,所以外部基本上不能访问,也可以隔绝外部黑客的入侵等.直接暴露外部是非常不安全的,特别是没有什么安全验证,容易被别人入侵做一些非法的事情! 所以,希望 ...
- SSH远程连接Linux配置
CentOS: 开启远程连接服务:service sshd start 添加到系统启动项:chkconfig sshd on 客户端工具:windows下连接工具putty ========= ...
- MySQL数据库远程访问权限如何打开(两种方法)
在我们使用mysql数据库时,有时我们的程序与数据库不在同一机器上,这时我们需要远程访问数据库.缺省状态下,mysql的用户没有远程访问的权限. 下面介绍两种方法,解决这一问题. 1.改表法 可能是你 ...
- CentOS最小化安装(一)
一.配置网络 切记记得配置DNS,否则Ping不通 在目录中进行网络配置文件的查找: /etc/sysconfig/network-scripts/ 1 1 /etc/sysconfig/net ...
- Turning off “Language Service Disabled” error message in VS2017
We are getting the following "Error" message in our MVC web application in Visual studio 2 ...
- [UFLDL] Basic Concept
博客内容取材于:http://www.cnblogs.com/tornadomeet/archive/2012/06/24/2560261.html 参考资料: UFLDL wiki UFLDL St ...
- iOS手机淘宝加入购物车动画分析
本文转载至 http://www.jianshu.com/p/e77e3ce8ee24 1.最终效果 仿淘宝动画 2.核心代码 _cartAnimView=[[UIImageView alloc] i ...
- mysql5.5 报Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
通过yum 的webstatic源安装的mysql55w-server,然后用service mysqld start启动时报 MySQL Daemon failed to start.Startin ...
- SSM项目实战
1. 实战才是检验学的怎么样的标准,一个小项目,运行老是出错,加上自己一贯的马虎的习惯,不严谨,就使学习之路更加的曲折了,感觉自己在这一行中比较吃力,但是自己选择了这条路,就得好好走下去,不要怀疑自 ...