题目简述:

Given a binary tree, find its minimum depth.

The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

解题思路:

# Definition for a  binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution:
# @param root, a tree node
# @return an integer
min = 99999
def minDeep(self, root, cur):
if root == None:
self.min = 0
return
cur += 1
if root.left == None and root.right ==None:
if self.min >cur:
self.min = cur
return if root.left != None:
self.minDeep(root.left, cur)
if root.right != None:
self.minDeep(root.right, cur) def minDepth(self, root):
self.minDeep(root, 0)
return self.min

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

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

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

  2. 【leetcode】Minimum Depth of Binary Tree (easy)

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

  3. 【Leetcode】【Easy】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】Maximum Depth of Binary Tree(二叉树的最大深度)

    这道题是LeetCode里的第104道题. 给出题目: 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定 ...

  5. 【LeetCode】Maximum Depth of Binary Tree

    http://oj.leetcode.com/problems/maximum-depth-of-binary-tree/ public class Solution { public int max ...

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

  7. [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)

    [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...

  8. LeetCode OJ Minimum Depth of Binary Tree 递归求解

        题目URL:https://leetcode.com/problems/minimum-depth-of-binary-tree/ 111. Minimum Depth of Binary T ...

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

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

随机推荐

  1. spring mvc 的jpa JpaRepository数据层 访问方式汇总

    本文转载至:http://perfy315.iteye.com/blog/1460226 AppleFramework在数据访问控制层采用了Spring Data作为这一层的解决方案,下面就对Spri ...

  2. 仿浏览器TAB效果

    仿浏览器的Tag标签 这里先上个非常非常简陋的demo,没加CSS,我先把jquery的源码给全部搞通,在专心把这个功能给讲一下 <!doctype html> <html lang ...

  3. html5图像组合

    一 图像组合 1.绘制阴影 在绘制阴影效果时,需要使用Canvas的多个属性配合完成 shadowBlur设置阴影的迷糊级数 shadowOffsetX设置形状与阴影的水平距离 shadowOffse ...

  4. U盘容量变小解决办法

    之前买了个三星闪盘,容量32G,USB3.0 后来装了U盘系统Kali Linux,最近想用的时候发现容量变为6GB了,真的很奇怪. 于是万能的百度(别说为什么不用谷歌,防火墙呀...) 找到解决办法 ...

  5. [译]Object.getPrototypeOf

    原文 概要 返回指定object的prototype. 语法 Object.getPrototypeOf(object) 参数 object 要返回原型的对象. 描述 当object参数不是一个对象的 ...

  6. shell if 浮点数比较

    转shell中的浮点数比较http://nigelzeng.iteye.com/blog/1604640 博客分类: Bash Shell shell比较浮点数  由于程序需要,我要判断一个浮点数是否 ...

  7. dom4j的小例子

    1.要解析的xml文件book.xml <?xml version="1.0" encoding="UTF-8"?> <books> & ...

  8. 【原创】CSS高效开发实战:CSS 3、LESS、SASS、Bootstrap、Foundation --读书笔记(5)使用放射渐变制作光影效果

    阴影效果通常用来表现光线投射在物体上的感觉,如果想制作一个如图5.19所示的文字光影效果,就可以使用背景的线性渐变进行构建. 图5.19可以看到有类似光束照射文字的效果,很好地突出了文字.这实现起来很 ...

  9. 使用自签名的方式创建Docker私有仓库

    Docker推荐使用CA机构颁发的TLS(Transport Layer Security Protocol)证书来保护docker仓库的安全,但是我们也可以选择使用HTTP或者自签名证书的方式实现本 ...

  10. intellij idea Maven 创建项目时出现的一些问题

    1.关于maven仓库的问题 在下载资源的时候特别慢,原因是因为天朝的网络你们都懂的.解决方式使用国内镜像,原本可以用的OSChina的镜像,由于其服务器关闭,现在无法使用. 解决方案是使用阿里云的m ...