
【python-leetcode111-树的宽度遍历】二叉树的最小深度
发布日期:2021-05-09 08:30:44
浏览次数:18
分类:博客文章
本文共 933 字,大约阅读时间需要 3 分钟。
������������������������������������������������
������������������������������������������������������������������������������������
������: ���������������������������������������������
������:
��������������� [3,9,20,null,null,15,7],
3
/ \ 9 20 / \ 15 7������������������������ 2.
# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution: def minDepth(self, root: TreeNode) -> int: if not root: return 0 queue=[root] res=[] depth=0 while queue: depth=depth+1 l=len(queue) for i in range(l): t=queue.pop(0) if not t.left and not t.right: return depth if t.left: queue.append(t.left) if t.right: queue.append(t.right)
发表评论
最新留言
做的很好,不错不错
[***.243.131.199]2025年04月29日 18时01分18秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
伪类选择器
2021-05-12
CSS列表 表格
2021-05-12
两正态总体参数的检验
2021-05-12
各种假设检验实例整理 R语言
2021-05-12
eclipse 连接android无法打出log问题汇总
2021-05-12
Spring学习笔记:AspectJ指示器
2021-05-12
Java学习笔记(多线程):volatile关键字
2021-05-12
spring security 的退出logout 和login404错误
2021-05-12
AO重要对象关系图
2021-05-12
Arcgis使用教程(十)ARCGIS地图制图之经纬网格添加
2021-05-12
ArrayList与LinkList区别
2021-05-12
Torch——masklect
2021-05-12
中国民生信托关注脱贫攻坚事业 荣获《亚洲银行家》“中国年度扶贫项目”奖
2021-05-12
一起挑战自我,享受旅途!维乐带你骑行在“死亡之海”
2021-05-12
proteus仿真之DS1302+LCD1602显示试验
2021-05-12
C# WinForm程序退出的方法
2021-05-12
ubuntu安装gem和fastlane
2021-05-12
onFailure unexpected end of stream
2021-05-12
android 集成weex
2021-05-12