leetcode之Minimum Depth of Binary Tree
来源:互联网 发布:淘宝网购物步骤 编辑:程序博客网 时间:2024/06/03 16:47
这题用的是广度抖索的方法。代码如下:
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): def minDepth(self, root): """ :type root: TreeNode :rtype: int """ if root == None: return 0 a = [root] num = 1 b = [] while True: for i in a: if i.left or i.right: if i.left: b.append(i.left) if i.right: b.append(i.right) else: return num else: num = num + 1 a = b[::] b = []
0 0
- LeetCode 之 Minimum Depth of Binary Tree
- LeetCode之Minimum Depth of Binary Tree
- LeetCode之Minimum Depth of Binary Tree
- leetcode之Minimum Depth of Binary Tree
- leetcode 之 Minimum Depth of Binary Tree
- leetcode之Minimum Depth of Binary Tree
- LeetCode之Minimum Depth of Binary Tree
- LeetCode 之 Minimum Depth of Binary Tree
- leetcode之Minimum Depth of Binary Tree
- leetcode之Minimum Depth of Binary Tree
- leetcode之Minimum Depth of Binary Tree
- LeetCode 之 Minimum Depth of Binary Tree
- LeetCode: Minimum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- LeetCode : Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- 使用DOM创建表格的完整流程
- setValuesForKeysWithDictionary崩溃问题
- Linux操作系统安装前备知识
- ScheduledExecutorService的使用
- OGNL表达式循环List<String[]>类型数据的方法
- leetcode之Minimum Depth of Binary Tree
- 文件下载 进度条
- 三种文件分配方式的区别
- Java 数组详解 - 用法、遍历、排序、实用API
- Centos 7 su root鉴证失败问题解决
- linux查看连接数
- 可以直接取出关卡名字this.currentLevelName
- Python处理验证码第一篇(pytesser初探及报错处理)
- 19-《电子入门趣谈》第三章_电子世界中的五官---传感器-3.2.4加速度传感器