mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
Merge pull request #1848 from Undertone0809/patch-3
Update 0104.二叉树的最大深度: 优化python代码
This commit is contained in:
@ -2532,20 +2532,18 @@ class Solution:
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
queue_ = [root]
|
queue_ = [root]
|
||||||
result = []
|
depth = 0
|
||||||
while queue_:
|
while queue_:
|
||||||
length = len(queue_)
|
length = len(queue_)
|
||||||
sub = []
|
|
||||||
for i in range(length):
|
for i in range(length):
|
||||||
cur = queue_.pop(0)
|
cur = queue_.pop(0)
|
||||||
sub.append(cur.val)
|
sub.append(cur.val)
|
||||||
#子节点入队列
|
#子节点入队列
|
||||||
if cur.left: queue_.append(cur.left)
|
if cur.left: queue_.append(cur.left)
|
||||||
if cur.right: queue_.append(cur.right)
|
if cur.right: queue_.append(cur.right)
|
||||||
result.append(sub)
|
depth += 1
|
||||||
|
|
||||||
|
return depth
|
||||||
return len(result)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
Reference in New Issue
Block a user