Skip to content

Commit 5f145da

Browse files
committed
Runtime: 0 ms (Top 100.00%) | Memory: 41.6 MB (Top 98.77%)
1 parent e3021a0 commit 5f145da

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

scripts/algorithms/P/Populating Next Right Pointers in Each Node II/Populating Next Right Pointers in Each Node II.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 0 ms (Top 100.00%) | Memory: 41.6 MB (Top 98.77%)
12
class Solution {
23
public Node connect(Node root) {
34
if (root == null) {
@@ -6,7 +7,7 @@ public Node connect(Node root) {
67
Node head = null; //the start node of next level, the first left of next level
78
Node prev = null; //the next pointer
89
Node curr = root;
9-
10+
1011
while (curr != null) {
1112
//traverse the whole current level, left -> right, until we meet a null pointer
1213
while (curr != null) {
@@ -19,8 +20,7 @@ public Node connect(Node root) {
1920
prev = prev.next;
2021
}
2122
}
22-
23-
23+
2424
if (curr.right != null) {
2525
if (head == null) {
2626
head = curr.right;
@@ -32,11 +32,11 @@ public Node connect(Node root) {
3232
}
3333
curr = curr.next;
3434
}
35-
35+
3636
curr = head;
3737
prev = null;
3838
head = null;
3939
}
4040
return root;
4141
}
42-
}
42+
}

0 commit comments

Comments
 (0)