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的更多相关文章

  1. 【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 ...

  2. 【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 ...

  3. 【LeetCode】104. Maximum Depth of Binary Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:BFS 方法二:DFS 参考资料 日期 题目 ...

  4. 【一天一道LeetCode】#104. Maximum Depth of Binary Tree

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 来源:http ...

  5. 【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 ...

  6. 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 ...

  7. [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 ...

  8. 【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 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. 中文转拼音,pinyin4j实用示例

    Pinyin4j是一个流行的Java库,支持中文字符和拼音之间的转换.拼音输出格式可以定制. Support Chinese character (both Simplified and Trandi ...

  2. PID应用详解

    PID应用详解 阅读目录 1.PID介绍及原理2.常用四轴的两种PID算法讲解(单环PID.串级PID)3.常用PID算法的C语言实现5.常用的四轴飞行器PID算法 PID介绍及原理 PID介绍 在工 ...

  3. 2019-11-29-asp-dotnet-core-通过图片统计-csdn-用户访问

    title author date CreateTime categories asp dotnet core 通过图片统计 csdn 用户访问 lindexi 2019-11-29 08:26:58 ...

  4. Linux操作系统的常用命令(一)

    一.写随笔的原因:上次提到centos7.3安装mysql5.7的一些步骤,恰巧最近面试有碰到一些问LInux操作的常用操作的问题,想通过这篇文章MARK一下,不一定能够全,只是用的比较多的吧(lin ...

  5. centso 7 Keepalived 配置脚本

    #!/bin/bash #This is keepalived bashshell. #MASTER/BACKUP yum install -y openssl openssl-devel keepa ...

  6. Foo, Bar的含义

    有些朋友问:foo, bar是什么意思, 为什么C++书籍中老见到这个词.我google了一下, 发现没有很好的中文答案.这个问题,在维基百科上有很好的回答.在这里翻译给大家. 译文: 术语fooba ...

  7. [全局最小割][Stoer-Wagner 算法] 无向图最小割

    带有图片例子的 [BLOG] 复杂度是$(n ^ 3)$ HDU3691 // #pragma GCC optimize(2) // #pragma GCC optimize(3) // #pragm ...

  8. python基础语法-Ⅲ

    Python注释 python中单行注释采用 # 开头. 实例 输出结果: 注释可以在语句或表达式行末: python 中多行注释使用三个单引号(''')或三个双引号(""&quo ...

  9. sublime text怎么格式化PHP代码

    手动安装: 可能由于各种原因,无法使用代码安装,那可以通过以下步骤手动安装Package Control: 1.点击Preferences > Browse Packages菜单 2.进入打开的 ...

  10. 13、Qt界面布局

    为了使设计的界面与运行后显示的一致,在main.cpp中添加代码,放在QApplication a(argc, argv);之前 #if (QT_VERSION >= QT_VERSION_CH ...