题目:

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. 阿铭linux笔记

    2015-09-06虚拟机网络设置.wmv: curl     获取在命令行显示的网页 dhclient     分配ip地址 ifdown eth0     关闭网卡eth0 ifup eh0   ...

  2. OAuth 2.0 开发完全详解

    --------------------------基础篇------------------------------- I:OAuth 2.0 概述 首先大家来看看国内新浪跟腾讯这两大头对OAuth ...

  3. iOS7适配问题

    iOS7适配问题 2013-09-28 08:32:37     我来说两句      作者:冻僵的企鹅 收藏    我要投稿 iOS 7发布了,适配问题来了,开发者都忙起来了. 先记一个iOS7 的 ...

  4. Effective Java2读书笔记-类和接口(一)

    第13条:使类和成员的可访问性最小化 设计良好的模块的模块与设计不好的模块区别在于,设计良好的模块会隐藏所有的实现细节,把它的API与他的实现清晰地隔离开来.然后模块之间只通过API通信. 信息隐藏之 ...

  5. spring的数据源基本配置

    aplictaionContext-dataSource的配置: <?xml version="1.0" encoding="utf-8"?> &l ...

  6. VirtualBox修改虚拟盘路径

    VirtualBox虚拟盘路径默认是存在C盘的,而当我们发现C盘不够用的时候,想转移就感觉有点麻烦了,现在给大家介绍一个简单又使用的方法. 第一步:到默认目录C:\Users\Administrato ...

  7. VIJOS 1052贾老二算算术 (高斯消元)

    描述 贾老二是个品学兼优的好学生,但由于智商问题,算术学得不是很好,尤其是在解方程这个方面.虽然他解决 2x=2 这样的方程游刃有余,但是对于 {x+y=3 x-y=1} 这样的方程组就束手无策了.于 ...

  8. CentOS 6.5配置nfs服务

    CentOS 6.5配置nfs服务 网络文件系统(Network File System,NFS),一种使用于分散式文件系统的协议,由升阳公司开发,于1984年向外公布.功能是通过网络让不同的机器.不 ...

  9. c#提出中文首字母

           ; i < len; i++)             {                 myStr += getSpell(strText.Substring(i, ));   ...

  10. windows多线程同步总结

    1.多线程同步与多线程互斥的关系 其实这也是我一直困扰的问题,在这里我只是说说我的理解.我的理解是多线程互斥是针对于多线程资源而言的. 而多线程同步是针对于多线程时序问题.由于线程的并发性导致其运行时 ...