【leetcode❤python】 111. Minimum Depth of Binary Tree
#-*- 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的更多相关文章
- 【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 ...
- 【LeetCode】111. Minimum Depth of Binary Tree 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 [LeetCode] 题目地址 ...
- 【一天一道LeetCode】#111. Minimum Depth of Binary Tree
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a ...
- 【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 ...
- 【easy】111. Minimum Depth of Binary Tree求二叉树的最小深度
求二叉树的最小深度: /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; ...
- [LeetCode] 111. Minimum Depth of Binary Tree ☆(二叉树的最小深度)
[Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 (最小有3种解法) 描述 解析 递归深度优先搜索 当求最大深度时,我们只要 ...
- [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 ...
- Leetcode 111 Minimum Depth of Binary Tree 二叉树
找出最短的从叶子到根的路径长 可以回忆Maximum Depth of Binary Tree的写法,只不过在!root,我把它改成了10000000,还有max函数改成了min函数,最后的值如果是1 ...
- [LeetCode]题解(python):111 Minimum Depth of Binary Tree
题目来源 https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minim ...
随机推荐
- My sql 日期格式化
DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据. 语法 DATE_FORMAT(date,format) select DATE_FORMAT(NOW(),'%Y-%m-%d %H ...
- R12 供应商SQL
-- 供应商主表数据: SELECT ass.vendor_id vendor_id, ass.party_id party_id, ass.segment1 vendor_code, ass.ven ...
- 夺命雷公狗ThinkPHP项目之----企业网站16之文章列表页的完善(关联查询)
我们栏目的所属栏目不能总是以数字来显示吧??这样的话,估计老板会让您直接卷铺盖滚蛋噢,嘻嘻... 所以我们需要对她进行关联查询,控制器代码如下所示: public function lists(){ ...
- PAT乙级 1023. 组个最小数 (20)
1023. 组个最小数 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CAO, Peng 给定数字0-9各若干个.你可以以 ...
- 六、Java基础---------equals 与 ==深入讲解
在我们写程序时经常会去比较两个变量是否相等,一般我们有两种方式去比较:equals与==,但是很多情况是不明就里,最后得出错误的结论.本文详解了equals与==. Java程序中测试两个变量是否的两 ...
- php 缓存加速器软件
Xcache 和 memcached 是两个不同层面的缓存,不存在可比性.Xcache 是 php 底层的缓存,它将PHP程式编译成字节码(byte code),再透过服务器上安装对应的程式来执行PH ...
- JavaScript:九种弹出对话框
[1.最基本的js弹出对话框窗口代码] 这是最基本的js弹出对话框,其实代码就几句非常简单: <script LANGUAGE="javascript"> <!- ...
- rsync增量传输大文件优化技巧
问题 rsync用来同步数据非常的好用,特别是增量同步.但是有一种情况如果不增加特定的参数就不是很好用了.比如你要同步多个几十个G的文件,然后网络突然断开了一下,这时候你重新启动增量同步.但是发现等了 ...
- javax.xml.ws.soap.SOAPFaultException: 没有Header,拦截器实施拦截
客户端代码: client.getOutInterceptors().add(new AuthInterceptor("zhangsan", "123456") ...
- 三种用于select 的选择器
<html lang="en"> <head> <meta charset="utf-8"> <title>选项 ...