#-*- coding: UTF-8 -*-
# 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):
    depthList=[]
    def minDepth(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        self.depthList=[]
        if root==None:return 0
        self.depthList.append(1)
        self.dfs(root)
       
        return min(self.depthList)
        
        
    def dfs(self,root):
        
        curdepth=self.depthList[-1]
        
        if root.right!=None or root.left!=None:
            self.depthList.pop()
        else:return
        
        if root.left!=None:
            dep=curdepth+1
            self.depthList.append(dep)
            self.dfs(root.left)
        if root.right!=None:
            dep=curdepth+1
            self.depthList.append(dep)
            self.dfs(root.right)

【leetcode❤python】 111. Minimum Depth of Binary Tree的更多相关文章

  1. 【LeetCode】111. Minimum Depth of Binary Tree (2 solutions)

    Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...

  2. 【LeetCode】111. Minimum Depth of Binary Tree 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 [LeetCode] 题目地址 ...

  3. 【一天一道LeetCode】#111. Minimum Depth of Binary Tree

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...

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

  5. 【easy】111. Minimum Depth of Binary Tree求二叉树的最小深度

    求二叉树的最小深度: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...

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

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

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

  8. Leetcode 111 Minimum Depth of Binary Tree 二叉树

    找出最短的从叶子到根的路径长 可以回忆Maximum Depth of Binary Tree的写法,只不过在!root,我把它改成了10000000,还有max函数改成了min函数,最后的值如果是1 ...

  9. [LeetCode]题解(python):111 Minimum Depth of Binary Tree

    题目来源 https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minim ...

随机推荐

  1. 说说oracle分页的sql语句

    说说oracle分页的sql语句,分排序和不排序两种. 当结果集不需要进行排序时,每页显示条数为:rowPerPage,当前页数为:currentPage. 1. 相对来说,这种查询速度会快一些,因为 ...

  2. ThinkPHP讲解(四)——视图

    本次讲解主要以<ThinkPHP开发手册>中“模板”一章中讲解为主 在MainController.class.php中新建一个操作方法Test() namespace Home\Cont ...

  3. 《zw版·delphi与halcon系列原创教程》zw版_THImagex控件函数列表

    <zw版·delphi与halcon系列原创教程>zw版_THImagex控件函数列表 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就要7w多行,但核心控件就是两 ...

  4. php字符串首字母转换大小写的实例

    in: 后端程序首字母变大写:ucwords() <?php$foo = 'hello world!';$foo = ucwords($foo); // Hello World!$bar = ' ...

  5. Mongodb 笔记09 备份、部署MongoDB

    备份 1. 只有在有信心能在紧急情况下完成迅速部署的情况下,备份才是有用的.所以,无论选择了哪种备份技术,一定要对备份及恢复备份的操作进行练习,知道了然于心. 2. 通常情况下,应对副本集的非主节点( ...

  6. 鸟哥的linux私房菜学习记录之认识与分析登录档

    logwatch分析登录档

  7. 【python cookbook】【数据结构与算法】8.与字典有关的计算问题

    问题:在字典上对数据执行各式各样的计算(比如求最小值.最大值.排序). 解决方案:利用zip()将字典的键-值对“反转”为值-键对序列. 例如:如下字典存放的股票名称和对应的价格: >>& ...

  8. React笔记_(4)_react语法3

    生命周期 很多语言中都讲了关于生命周期.这可是决定生命的周始,有没有存在感的关键啊. 生命周期,有生有死,有始有终,因果轮回,循环往复.(说多了) react中,主要说明的是 一个组件的生命周期.简单 ...

  9. alias function varibales in Linux/GNU and Mac alias命令细说

    细说,在古文言中是”奸细佞臣的话“,现如今成了”详细说明“的缩略. alias是MS-DOC中cmds中doskey的counterpart,是”别名“或者”化名“的意思 alias强大之处在于可以化 ...

  10. NEON在Android中的使用举例【转】

    转自:http://blog.csdn.net/fengbingchun/article/details/37766607 版权声明:本文为博主原创文章,未经博主允许不得转载. 1.  打开Eclip ...