Skip to content

Commit 32539c2

Browse files
committed
117. Populating Next Right Pointers in Each Node II
1 parent 8a9f413 commit 32539c2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
public void connect(TreeLinkNode root) {
3+
while(root != null){
4+
TreeLinkNode start = new TreeLinkNode(0);
5+
TreeLinkNode pointer = start;
6+
while(root != null){
7+
if(root.left != null){
8+
pointer.next = root.left;
9+
pointer = pointer.next;
10+
}
11+
if(root.right != null){
12+
pointer.next = root.right;
13+
pointer = pointer.next;
14+
}
15+
root = root.next;
16+
}
17+
root = start.next;
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)