# 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 root == None:
return 0
if root.left == None and root.right != None:
return self.maxDepth(root.right)+1
if root.left != None and root.right == None:
return self.maxDepth(root.left)+1
return max(self.maxDepth(root.left),self.maxDepth(root.right))+1

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

  1. LeetCode——Maximum Depth of Binary Tree

    LeetCode--Maximum Depth of Binary Tree Question Given a binary tree, find its maximum depth. The max ...

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

  3. Leetcode 104 Maximum Depth of Binary Tree python

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

  4. leetcode:Maximum Depth of Binary Tree【Python版】

    # Definition for a binary tree node # class TreeNode: # def __init__(self, x): # self.val = x # self ...

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

  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 dfs,深度搜索

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

  8. LeetCode Maximum Depth of Binary Tree (求树的深度)

    题意:给一棵二叉树,求其深度. 思路:递归比较简洁,先求左子树深度,再求右子树深度,比较其结果,返回:max_one+1. /** * Definition for a binary tree nod ...

  9. leetcode Minimum Depth of Binary Tree python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

随机推荐

  1. SecureCRT中文显示乱码的解决方法

    注:本文出自:http://riching.iteye.com/blog/349754 最近开始用SecureCRT登陆linux系统,由于是新手,很多问题不清楚,碰到显示中文乱码的问题,困扰了好几天 ...

  2. [代码]Java后台推送消息到IOS前端

    PayLoad payLoad = new PayLoad(); payLoad.addAlert("test");    //手机端的提示消息 payLoad.addBadge( ...

  3. 利用SQL语句产生分组序号

    partition  by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition  by用于给结果集分组,如果没 ...

  4. spark on yarn :state: ACCEPTED一直 出现

    今天运行spark on yarn 一直出现 16/09/20 18:40:41 INFO yarn.Client: Application report for application_147417 ...

  5. java之方法覆盖的坑

    昨天写了个小例子,覆盖hashCode.equals进行集合set的一些特性测试,代码如下: class Test3 { public int c; public Test3(int c) {this ...

  6. juce中的内存泄漏检测

    非常值得借鉴的做法,基于引用计数和局部静态变量,代码比较简单不加详解. //============================================================== ...

  7. PHP中简单的图形处理

    PHP中简单的图形处理 计应134凌豪 1.加载GD库 GD库是一个开放的动态创建图像.源代码公开的函数库,可以从官方网站http://www.boutell.com/gd处下载.目前,GD库支持GI ...

  8. 习惯使用断言Assert

    一直在给党做项目,我们这些可怜兮兮的学生都没太多时间安排自己的活动了,写个blog都要在中午休息的时间. 项目用的是.NET,本来也想分享一些干货点的东西,但博客园里的前辈把这类文章已经分享泛滥了,想 ...

  9. Session和Cookie的关系

    Session和Cookie关系 两者构建了web的回话数据 Cookie作为客户端的回话,Session为服务器端的 共同点: 都是1对1的,(一个客户一个独立的回话) 都以键值对的方式存储数据 都 ...

  10. JavaMail回复

    JavaMail邮件回复 http://blog.csdn.net/o_darling/article/details/17558049 http://blog.csdn.net/xiyang_199 ...