Skip to content

Commit 2c781aa

Browse files
authored
Refactor queue operations to use offerLast
1 parent 027a40b commit 2c781aa

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

solution/0100-0199/0117.Populating Next Right Pointers in Each Node II/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,20 @@ class Solution {
148148
return root;
149149
}
150150
Deque<Node> q = new ArrayDeque<>();
151-
q.offer(root);
151+
q.offerLast(root);
152152
while (!q.isEmpty()) {
153153
Node p = null;
154154
for (int n = q.size(); n > 0; --n) {
155-
Node node = q.poll();
155+
Node node = q.pollFirst();
156156
if (p != null) {
157157
p.next = node;
158158
}
159159
p = node;
160160
if (node.left != null) {
161-
q.offer(node.left);
161+
q.offerLast(node.left);
162162
}
163163
if (node.right != null) {
164-
q.offer(node.right);
164+
q.offerLast(node.right);
165165
}
166166
}
167167
}

0 commit comments

Comments
 (0)