leetcode Populating Next Right Pointers in Each Node

时间:2014-05-22 03:03:39   收藏:0   阅读:183
bubuko.com,布布扣
/**
根据完美二叉树或者非完美二叉树都可以,利用左右子树的根节点的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); }
bubuko.com,布布扣

 

leetcode Populating Next Right Pointers in Each Node,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!