#-*- coding: UTF-8 -*-
# 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):
        if root==None:return 0
        leftDepth=self.maxDepth(root.left)
        rightDepth=self.maxDepth(root.right)
        
        return leftDepth+1 if leftDepth >rightDepth else (rightDepth+1)

【leetcode❤python】 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 OJ】Maximum Depth of Binary Tree

    Problem Link: https://oj.leetcode.com/problems/maximum-depth-of-binary-tree/ Simply BFS from root an ...

  3. 【LeetCode练习题】Minimum Depth of Binary Tree

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  4. 【LeetCode OJ】Minimum Depth of Binary Tree

    Problem Link: http://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ To find the minimum dept ...

  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刷题笔记】Maximum Depth of Binary Tree

    Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...

  7. 【LeetCode】Maximum Depth of Binary Tree(二叉树的最大深度)

    这道题是LeetCode里的第104道题. 给出题目: 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定 ...

  8. 【leetnode刷题笔记】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#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 ...

随机推荐

  1. RMAN备份演练进阶篇

    前篇介绍了通过rman进行各种备份,进阶篇则主要是rman的一些功能扩展和增加功能,利用前篇你已经完全可以完成数据库的备份,而通过本篇你可以更好更方便的完成数据库的备份. 一.建立增量备份 如果数据库 ...

  2. Java魔法堂:注释和注释模板 (转)

    http://www.cnblogs.com/fsjohnhuang/p/3988883.html 一.注释   1. 注释类型 [a]. 单行注释 // 单行注释 String type = &qu ...

  3. Java 中的System.exit

    在java 中退出程序,经常会使用System.exit(1) 或 System.exit(0). 查看System.exit()方法的源码,如下 /** * Terminates the curre ...

  4. 新发现了一个编辑器HBuilder,感觉蛮好的,关键是国产软件。

    http://www.dcloud.io/

  5. equals和==

    在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String("hello"); 2 String str2 = new String(&qu ...

  6. FireDac 的数据库批量语句提交(高效)

    FD 提供了批量执行功能, 称为 Array DML. 可以这么做: FDQuery1.SQL.Text := 'insert into MyTab values (:p1, :p2, :p3)'; ...

  7. CSS的样式合并与模块化

    by zhangxinxu from http://www.zhangxinxu.com 原文地址:http://www.zhangxinxu.com/wordpress/?p=931 一.引言 本文 ...

  8. alias function varibales in Linux/GNU and Mac alias命令细说

    细说,在古文言中是”奸细佞臣的话“,现如今成了”详细说明“的缩略. alias是MS-DOC中cmds中doskey的counterpart,是”别名“或者”化名“的意思 alias强大之处在于可以化 ...

  9. 使用jprofiler8远程监控weblogic的配置方法

    jprofiler8的注册码:L-Larry_Lau@163.com#36573-fdkscp15axjj6#25257 未完待续

  10. 【Pro ASP.NET MVC 3 Framework】.学习笔记.4.MVC的主要工具-使用Moq

    在之前的例子中,我们创建了FakeRepository类来支持我们的测试.但是我们还没有解释如何穿件一个真实的repository实现,我们需要一个替代品.一旦我们有一个真的实现,我们可能不会再用它, ...