#-*- 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. em和rem及rem在移动的应用

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <style t ...

  2. Repeater 时间格式化

    Repeater 时间格式化   <%# Eval("AboutDate","{0:yyyy-MM-dd hh:mm:ss}")%> 个人认为最好用 ...

  3. php里session的用法

    PHP中的session默认情况下是使用客户端的Cookie.当客户端的Cookie被禁用时,会自动通过Query_String来传递. Php处理会话的函数一共有11个,我们详细介绍一下将要用到几个 ...

  4. laravel 目录结构

    图 1.1 显示了 Laravel 项目目录结构是什么样子: 图1.1 Laravel 项目目录结构 就如你看到这样,laravel下面只包含了4个文件夹,这4个文件夹下面有一些子文件夹,这种丰富的子 ...

  5. java多线程中的生产者与消费者之等待唤醒机制@Version1.0

    一.生产者消费者模式的学生类成员变量生产与消费demo,第一版1.等待唤醒:    Object类中提供了三个方法:    wait():等待    notify():唤醒单个线程    notify ...

  6. php curl语句的用法

    system32文件夹下,修改php.ini文件,找到;extension= php_curl.dll行,去掉前面的;号,保存,重启服务器.在站点目录下建立一个PHP文件,内容如下 $ch = cur ...

  7. hashcode与equals

    归纳一下就是hashCode是用于查找使用的,而equals是用于比较两个对象的是否相等的.以下这段话是从别人帖子回复拷贝过来的: .hashcode是用来查找的,如果你学过数据结构就应该知道,在查找 ...

  8. 【转】java URLConnection从网上下载图片或音乐

    try { //根据String形式创建一个URL对象,   URL url = new URL("http://www.baidu.com");   //实列一个URLconne ...

  9. SQL Server 索引和表体系结构(二)

    转自:http://www.cnblogs.com/chenmh 非聚集索引 概述 对于非聚集索引,涉及的信息要比聚集索引更多一些,由于整个篇幅比较大涉及接下来的要写的“包含列的索引”,“索引碎片”等 ...

  10. The shortest problem

    The shortest problem Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...