## [111\. 二叉树的最小深度](https://leetcode-cn.com/problems/minimum-depth-of-binary-tree/)
>Easy
#### 思路
* 求最小的深度,那我们自然想到使用层序遍历,使用广度优先算法。
* 碰到第一个没有子元素的节点,说明是就是最近的子节点。
* 每向下走一层,记录一下层号。
* 没有子节点,结束遍历,返回结果
综上,尝试写一下代码,AC!
#### 代码
python3
```
class Solution:
def minDepth(self, root: TreeNode) -> int:
if root is None:
return 0
queue = [{'item':root,'depth': 1}]
while len(queue):
node = queue[0]['item']
depth = queue[0]['depth']
del queue[0]
if node.left is None and node.right is None:
return depth
if node.left is not None:
queue.append({'item':node.left,'depth': depth + 1})
if node.right is not None:
queue.append({'item':node.right,'depth': depth + 1})
return 0
```
- 目录
- excel-sheet-column-number
- divide-two-integers
- house-robber
- fraction-to-recurring-decimal
- profile
- kids-with-the-greatest-number-of-candies
- qiu-12n-lcof
- new-21-game
- product-of-array-except-self
- minimum-depth-of-binary-tree
- univalued-binary-tree
- shun-shi-zhen-da-yin-ju-zhen-lcof
- permutations
- satisfiability-of-equality-equations
- word-ladder-ii
- ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof
- palindrome-number
- network-delay-time
- daily-temperatures
- longest-common-prefix
- sum-of-mutated-array-closest-to-target
- 周赛专题
- make-two-arrays-equal-by-reversing-sub-arrays
- check-if-a-string-contains-all-binary-codes-of-size-k
- course-schedule-iv
- cherry-pickup-ii
- maximum-product-of-two-elements-in-an-array
- maximum-area-of-a-piece-of-cake-after-horizontal-and-vertical-cuts
- reorder-routes-to-make-all-paths-lead-to-the-city-zero
- probability-of-a-two-boxes-having-the-same-number-of-distinct-balls
- shuffle-the-array
- the-k-strongest-values-in-an-array
- design-browser-history
- paint-house-iii
- final-prices-with-a-special-discount-in-a-shop