Skip to content

Commit 6b946fb

Browse files
committed
Update 116. 填充每个节点的下一个右侧节点指针
1 parent 847edaf commit 6b946fb

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

algorithms/populating-next-right-pointers-in-each-node.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,8 @@ function bfs(root) {
4444

4545
while (size--) {
4646
const node = queue.shift();
47-
if (size === 0) {
48-
node.next = null;
49-
} else {
50-
const top = queue[0];
51-
node.next = top;
52-
}
47+
node.next = size === 0 ? null : queue[0];
48+
5349
node.left && queue.push(node.left);
5450
node.right && queue.push(node.right);
5551
}

0 commit comments

Comments
 (0)