mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +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
|
||||
|
||||
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