mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 11:34:46 +08:00
Update 0102.二叉树的层序遍历.md
This commit is contained in:
@ -98,12 +98,12 @@ class Solution:
|
|||||||
out_list = []
|
out_list = []
|
||||||
|
|
||||||
while quene:
|
while quene:
|
||||||
length = len(queue) # 这里一定要先求出队列的长度,不能用range(len(queue)),因为queue长度是变化的
|
length = len(queue) # 这里一定要先求出队列的长度,不能用range(len(queue)),因为queue长度是变化的
|
||||||
in_list = []
|
in_list = []
|
||||||
for _ in range(length):
|
for _ in range(length):
|
||||||
curnode = queue.pop(0) #(默认移除列表最后一个元素)这里需要移除队列最头上的那个
|
curnode = queue.pop(0) # (默认移除列表最后一个元素)这里需要移除队列最头上的那个
|
||||||
in_list.append(curnode.val)
|
in_list.append(curnode.val)
|
||||||
if curnode.left : queue.append(curnode.left)
|
if curnode.left: queue.append(curnode.left)
|
||||||
if curnode.right: queue.append(curnode.right)
|
if curnode.right: queue.append(curnode.right)
|
||||||
out_list.append(in_list)
|
out_list.append(in_list)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user