题目:

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.

求二叉树的深度,递归一下就可以求到了。

python新手(我)发现python中没有三元运算符,不过可以用true_part if condition else false_part模拟。虽然我后面用max函数代替了三元运算符,也实现了功能。

 class Solution(object):
def maxDepth(self, root):
if (root == None):
return 0
left_depth = self.maxDepth(root.left)
right_depth = self.maxDepth(root.right)
return max(left_depth, right_depth) + 1

Leetcode 104 Maximum Depth of Binary Tree python的更多相关文章

  1. LeetCode 104. Maximum Depth of Binary Tree C++ 解题报告

    104. Maximum Depth of Binary Tree -- Easy 方法 使用递归 /** * Definition for a binary tree node. * struct ...

  2. leetcode 104 Maximum Depth of Binary Tree二叉树求深度

    Maximum Depth of Binary Tree Total Accepted: 63668 Total Submissions: 141121 My Submissions Question ...

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

  4. (二叉树 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 ...

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

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

  7. LeetCode 104. Maximum Depth of Binary Tree

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

  8. leetcode 104 Maximum Depth of Binary Tree ----- java

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

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

随机推荐

  1. sudo 无法解析主机的解决办法

    错误存在于更改主机名字后,解决办法如下: sudo gedit /etc/hosts找到如下行:127.0.1.1       XXX将其修改为:127.0.1.1       (你现在的主机名) 保 ...

  2. hasOwnProperty方法的使用

    JavaScript中hasOwnProperty函数方法是返回一个布尔值,指出一个对象是否具有指定名称的属性. 使用方法: object.hasOwnProperty(proName)其中参数obj ...

  3. UIAutomator 学习版

    1.要写UIAutomator的testcase,首先要用Eclipse创建一个Java Project 需要将Junit 的lib加入到工程里 2.添加android.jar和uiautomator ...

  4. hex、bin、elf、axf文件区别

    AXF和ELF axf文件是ARM的调试文件,除了包含bin的内容之外,还附加了其他的调试信息,这些调试信息加在可执行的二进制数据的前面.在调试的时候,这些调试信息是不必下到RAM中去的,真正下到RA ...

  5. PLSQL 循环示例

    <pre name="code" class="sql"><pre name="code" class="sql ...

  6. 优化C#程序的48种方法

    一.用属性代替可访问的字段 1..NET数据绑定只支持数据绑定,使用属性可以获得数据绑定的好处: 2.在属性的get和set访问器重可使用lock添加多线程的支持. 二.readonly(运行时常量) ...

  7. JAVA大整数傻瓜入门

    http://blog.csdn.net/skiffloveblue/article/details/7032290..先记着

  8. poj 3579 Median (二分搜索之查找第k大的值)

    Description Given N numbers, X1, X2, ... , XN, let us calculate the difference of every pair of numb ...

  9. 新建一个MVCProject 项目

    App_Data文件夹用于存放数据库文件的 App_Start文件夹用于存放Web应用程序启动时需要进行重要配置的类文件 Content 文件夹用于存放主题样式文件 Controllers 文件夹用于 ...

  10. JQuery Ajax 获取数据

    前台页面:   对一张进行查询,删除,添加 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"& ...