您的位置:首页 > Web前端 > Node.js

leetcode Populating Next Right Pointers in Each Node

2014-05-20 11:18 253 查看
/**
根据完美二叉树或者非完美二叉树都可以,利用左右子树的根节点的next节点信息来连接next
*/
public void connect(TreeLinkNode root){
if(root==null)
return;
//利用父节点的next链接节点
if(root.left!=null){
root.left.next=root.right;
}
if(root.right!=null&&root.next!=null){
root.right.next=root.next.left;
}
connect(root.left);
connect(root.right);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: