mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
Merge branch 'master' into my-contribution
This commit is contained in:
@@ -23,7 +23,9 @@
|
||||
* 111.二叉树的最小深度
|
||||
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
|
||||
@@ -53,7 +55,7 @@
|
||||
|
||||
使用队列实现二叉树广度优先遍历,动画如下:
|
||||
|
||||

|
||||

|
||||
|
||||
这样就实现了层序从左到右遍历二叉树。
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user