leetcode-easy-trees-Maximum Depth of Binary Tree
mycode 92.69%
# 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 not root:
return 0
return max(self.maxDepth(root.left),self.maxDepth(root.right))+1
参考
# 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 not root:
return 0
left = self.maxDepth(root.left)
right = self.maxDepth(root.right)
return max(left, right) + 1
leetcode-easy-trees-Maximum Depth of Binary Tree的更多相关文章
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- 【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
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源:http ...
- 【Leetcode】【Easy】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(easy)
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- [LeetCode#104, 111]Maximum Depth of Binary Tree, Minimum Depth of Binary Tree
The problem 1: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes ...
- 【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 OJ 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 OJ:Maximum Depth of Binary Tree(二叉树最大深度)
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
随机推荐
- HDFS NFS Gateway
NFS网关支持NFSv3,并允许将HDFS作为客户端本地文件系统进行挂载.目前,NFS Gateway支持并启用以下使用模式: 用户可以通过NFSv3客户端兼容操作系统上的本地文件系统浏览HDFS文件 ...
- Centos7:dubbo监控中心安装,配置和使用
制作dubbo-admin.war文件 下载dubbo-admin https://github.com/alibaba/dubbo 注:2.6版本后源码中不包含dubbo-admin工程 在dubb ...
- Vue中,过滤器的使用方法!
Vue.js允许自定义过滤器,可被用于一些常见的文本格式化.过滤器可以用在两个地方:双花括号插值和v-bind表达式.过滤器应该被添加在JavaScript表达式的尾部,由“管道”符号指示:(借官方的 ...
- AngularJS 在实际应用中优缺点
AngularJS 在实际应用中优点:模板功能强大丰富,并且是声明式的,自带了丰富的Angular指令:是一个比较完善的前端MV*框架,包含模板,数据双向绑定,路由,模块化,服务,过滤器,依赖注入等所 ...
- shell 脚本中的入参获取与判断
1.获取shell脚本的入参个数: $# 2.获取shell脚本的第n个入参的字符个数/字符串长度(注意这里的n需要替换为具体的数字,如果这个数字超过实际的入参个数,结果为0): ${#n}
- 05-spring框架—— Spring 事务
5.1 Spring 的事务管理 事务原本是数据库中的概念,在 Dao 层.但一般情况下,需要将事务提升到业务层,即 Service 层.这样做是为了能够使用事务的特性来管理具体的业务. 在 Spri ...
- 【AGC 036C】GP2
https://atcoder.jp/contests/agc036/tasks/agc036_c 题意 有一个长度为 $n$ 的非负整数序列 $x$,初始时全为 $0$.一次操作定义为选择一对正整数 ...
- Python——枚举(enum)
- Ruby笔记
1.数组遍历方法总结 array = (1..10).to_a length = array.length length.times do t print "#{array[t]} &quo ...
- Wpf自动滚动效果
一.思路 1.使用ScrollView的Scroll.ScrollToVerticalOffset(offset)方法进行滚动 2.ScrollView中放置2个ListView,第一个滚动出边界后, ...