117. Populating Next Right Pointers in Each Node II

//按层从左往右检索
public class Solution {
public void connect(TreeLinkNode root) {
while (root != null) {
TreeLinkNode tempChild = new TreeLinkNode(0);
TreeLinkNode currentChild = tempChild;
while (root != null) {
if (root.left != null) {
currentChild.next = root.left;
currentChild = currentChild.next;
}
if (root.right != null) {
currentChild.next = root.right;
currentChild = currentChild.next;
}
root = root.next;
}
root = tempChild.next;
}
}
}
浙公网安备 33010602011771号