mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 06:26:08 +00:00
build
This commit is contained in:
@@ -124,13 +124,10 @@ comments: true
|
||||
// 初始化一个列表,用于保存遍历序列
|
||||
const list = [];
|
||||
while (queue.length) {
|
||||
let node = queue.shift(); // 队列出队
|
||||
list.push(node.val); // 保存节点值
|
||||
if (node.left)
|
||||
queue.push(node.left); // 左子节点入队
|
||||
if (node.right)
|
||||
queue.push(node.right); // 右子节点入队
|
||||
|
||||
let node = queue.shift(); // 队列出队
|
||||
list.push(node.val); // 保存节点值
|
||||
if (node.left) queue.push(node.left); // 左子节点入队
|
||||
if (node.right) queue.push(node.right); // 右子节点入队
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user