题目
解题
- 这个题的难点是两个相邻节点却不是同一个父亲的next的设置。
- 注意这个颗树是完全二叉树。
public class Solution{
public void connect(TreeLinkNode root){
if(root==null)return;
while(root.left!=null){
TreeLinkNode node=root;
while(node!=null){
node.left.next=node.right;
if(node.next!=null){
node.right.next=node.next.left;
}
node = node.next;//向右移动
}
root=root.left;//回到最左边。
}
}
}