-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP_117.java
More file actions
31 lines (27 loc) · 777 Bytes
/
Copy pathP_117.java
File metadata and controls
31 lines (27 loc) · 777 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package leetcode.medium;
import utils.DataStructures.Node;
public class P_117 {
public Node connect(Node root) {
final Node res = root;
while (root != null) {
final Node level = new Node(0);
Node curr = level;
while (root != null) {
if (root.left != null) {
curr.next = root.left;
curr = curr.next;
}
if (root.right != null) {
curr.next = root.right;
curr = curr.next;
}
root = root.next;
}
root = level.next;
}
return res;
}
public Node connectBFS(Node root) {
return P_116.connectBFS(root);
}
}