I know my solution is a long one, but it comes to me at the beginning since this problem can be solved by the same idea as the previous one (which use complete binary tree instead of any binary tree)

so my solution derived from the complete one is

```
public void connect(TreeLinkNode root) {
if (root == null) {return;}
TreeLinkNode start = root;
while (start != null) {
TreeLinkNode curt = start;
while (curt != null) {
if (curt.left != null && curt.right != null) {curt.left.next = curt.right;}
if (curt.next != null) {
TreeLinkNode temp = curt.next;
if (curt.right != null) {
if (temp.left != null) {curt.right.next = temp.left;}
else if (temp.right != null) {curt.right.next = temp.right;}
}
else if (curt.left != null) {
if (temp.left != null) {curt.left.next = temp.left;}
else if (temp.right != null) {curt.left.next = temp.right;}
}
}
curt = curt.next;
}
start = start.left;
}
return;
}
```

which derived from the previous solution

```
public void connect(TreeLinkNode root) {
if (root == null) {return;}
TreeLinkNode start = root;
while (start != null) {
TreeLinkNode curt = start;
while (curt != null) {
if (curt.left != null) {curt.left.next = curt.right;}
if (curt.right != null && curt.next != null) {curt.right.next = curt.next.left;}
curt = curt.next;
}
if (start.left != null) {start = start.left;}
else {start = start.right;}
}
}
```

but somehow it doesn't work, it pass 30 test cases but fail at the 30/61

in which the test case is

Output:

{1,#,2,3,#,4,5,6,#,7,#}

Expected:

{1,#,2,3,#,4,5,6,#,7,8,#}

can anyone help? thx a lot