Merge branch 'master' into my-contribution

This commit is contained in:
程序员Carl
2023-01-19 10:40:36 +08:00
committed by GitHub
61 changed files with 708 additions and 294 deletions

View File

@@ -23,7 +23,9 @@
* 111.二叉树的最小深度
![我要打十个](https://tva1.sinaimg.cn/large/008eGmZEly1gPnadnltbpjg309603w4qp.gif)
![我要打十个](https://code-thinking.cdn.bcebos.com/gifs/%E6%88%91%E8%A6%81%E6%89%93%E5%8D%81%E4%B8%AA.gif)
@@ -53,7 +55,7 @@
使用队列实现二叉树广度优先遍历,动画如下:
![102二叉树的层序遍历](https://tva1.sinaimg.cn/large/008eGmZEly1gnad5itmk8g30iw0cqe83.gif)
![102二叉树的层序遍历](https://code-thinking.cdn.bcebos.com/gifs/102%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%B1%82%E5%BA%8F%E9%81%8D%E5%8E%86.gif)
这样就实现了层序从左到右遍历二叉树。
@@ -2532,20 +2534,18 @@ class Solution:
return 0
queue_ = [root]
result = []
depth = 0
while queue_:
length = len(queue_)
sub = []
for i in range(length):
cur = queue_.pop(0)
sub.append(cur.val)
#子节点入队列
if cur.left: queue_.append(cur.left)
if cur.right: queue_.append(cur.right)
result.append(sub)
depth += 1
return len(result)
return depth
```
Go