117. Populating Next Right Pointers in Each Node II
public class Solution {
public void connect(TreeLinkNode root) {
TreeLinkNode lstart=new TreeLinkNode(0);
while(root!=null)
{
TreeLinkNode cur=lstart;
while(root!=null)
{
if(root.left!=null)
{
cur.next=root.left;
cur=cur.next;
}
if(root.right!=null)
{
cur.next=root.right;
cur=cur.next;
}
root=root.next;
}
root=lstart.next;
lstart.next=null;
}
}
}

浙公网安备 33010602011771号