# 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. jquery选择器从认识到使用初级篇

    1.   .class 选择器 ---一种通过元素类别属性查找元素 调用格式: $(".class") ----其中参数表示元素的css类别名称(类选择器)<input cl ...

  2. 怎么使用dreamweaver制作网页教程 dw建站设计网页

    对于网页制作相关专业人士一定对dreamweaver有所认识,下面小编就问大家总结一下相关网页制作的一些步骤,喜欢的朋友可以一起来学习一下   Dreamweaver这一款专业的网页制作软件,相信相关 ...

  3. 用GoEasy推送实现Java实时推送

    前段时间客户有个需求他希望他在后台管理页面发布一个消息,所有用这个系统的用户无论在哪个页面都能及时收到他发布的信息,以前对于类似需求在少量 页面接收的前提下,我一般采用ajax定时去服务器pull信息 ...

  4. 端口扫描器之java实现

    端口扫描器之java实现   import java.net.*;import java.io.*;import java.awt.*;import java.awt.event.*;import j ...

  5. [stack]Evaluate Reverse Polish Notation

    Total Accepted: 55722 Total Submissions: 249668 Difficulty: Medium Evaluate the value of an arithmet ...

  6. 用SQL将查询出来的多列的值拼接成一个字符串【转载】

    MySQL中: [sql] view plaincopyprint? -- 单列拼接,先查出一行,再加上逗号,接着拼接 查出的下一行 select group_concat(E.SUPPORT) fr ...

  7. js删除数组里的某个元素

    首先可以给js的数组对象定义一个函数,用于查找指定的元素在数组中的位置,即索引,代码为: Array.prototype.indexOf = function(val) { for (var i = ...

  8. android 连接网络的简单实例

    1.android有两种连接网络的类HttpURLConnect和HttpClient,但是HttpClient已逐渐被HttpURLConnect类代替所以就不提及. 2.实例 String add ...

  9. php 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等

    /** * 查找数组中是否存在某项,并返回指定的字符串,可用于检查复选,单选等 * @param $id * @param $ids * @param string $returnstr * @ret ...

  10. 动态创建分页 LINQ+EF

    public class Message { public int MessageId { get; set; } public string MessageTitle { get; set; } p ...