# 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 minDepth(self, root):
"""
:type root: TreeNode
:rtype: int
"""
if root == None:
return 0
if root.left == None and root.right != None:
return self.minDepth(root.right)+1
if root.left != None and root.right == None:
return self.minDepth(root.left)+1
return min(self.minDepth(root.right),self.minDepth(root.left))+1

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

  1. LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree

    LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...

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

  3. [LeetCode] Minimum Depth of Binary Tree 二叉树的最小深度

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

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

    1.类中递归调用添加self: 2.root为None,返回0 3.root不为None,root左右孩子为None,返回1 4.返回l和r最小深度,l和r初始为极大值: # Definition f ...

  5. LeetCode - Minimum Depth of Binary Tree

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

  6. [LeetCode] Minimum Depth of Binary Tree 二叉树最小深度

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

  7. leetcode Maximum Depth of Binary Tree python

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

  8. LeetCode Minimum Depth of Binary Tree 找最小深度(返回最小深度)

    题意:找到离根结点最近的叶子结点的那一层(设同一层上的结点与根结点的距离相等),返回它所在的层数. 方法有: 1.递归深度搜索 2.层次搜索 方法一:递归(无优化) /** * Definition ...

  9. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

随机推荐

  1. 卓尼斯ZT-180评測

    卓尼斯ZT-180评測    ——正在出差途中,用10”上网本发帖,没有拍照,且写得冲忙,不妥之处见谅. 一.採购 1.因外出旅游,不想带那台14"笔记本,所以想买一台平板电脑.当时,选择的 ...

  2. Javascript 中的false,零值,null,undefined和空字符串对象

    在Javascript中,我们经常会接触到题目中提到的这5个比较特别的对象--false.0.空字符串.null和undefined.这几个对象很容易用错,因此在使用时必须得小心. 类型检测 我们下来 ...

  3. IDE idea 更换项目的JDK步骤

    1.如图:

  4. beforefieldinit释义(3)

    1.看下面的例子: public static class MyClass<T> { public static readonly DateTime Time = GetNow(); pr ...

  5. Spring-----代码中使用注入的Properties配置属性

    转载自:http://blog.csdn.net/hekewangzi/article/details/49990799

  6. html5新增结构元素

    1.article元素代表文档.页面或应用程序中独立的.完整的.可以独自被外部引用的内容.除了内容外,一个article元素还有它自己的标题(一般放在header里),有时还有自己的脚注. 2.sec ...

  7. PendingIntent Bundle null解决方案

    在安卓开发中,用通知栏,如果点击通知栏条目,跳转Intent需要传值的时候会出现问题,传入值失败. Intent intent; PendingIntent sender=PendingIntent. ...

  8. javascript定时器(上)

    (一).setInterval 间隔性 function show(){ alert(‘a’); } setInterval(show,1000); 每隔1000毫秒(1秒)执行一次show这个函数: ...

  9. Spring与Mybatis配置问题

    Spring和Mybatis的整合,主要借助于Spring的依赖注入和控制反转来简化Mybatis的配置,使用两个配置文件[注:此种配置文件网上已经有很多]: spring.xml: <?xml ...

  10. div 居中CSS实现

    .login-box { position: absolute; border: solid #E3EAE7 1px; top: 50%; left: 50%; margin: -100px 0 0 ...