首页 > 其他 > 详细

117. Populating Next Right Pointers in Each Node II

时间:2019-03-15 13:30:13      阅读:178      评论:0      收藏:0      [点我收藏+]

 

技术分享图片

 

//按层从左往右检索
public class Solution {
    public void connect(TreeLinkNode root) {
        
        while (root != null) {
            TreeLinkNode tempChild = new TreeLinkNode(0);
            TreeLinkNode currentChild = tempChild;
            while (root != null) {
                if (root.left != null) {
                    currentChild.next = root.left;
                    currentChild = currentChild.next;
                }
                if (root.right != null) {
                    currentChild.next = root.right;
                    currentChild = currentChild.next;
                }
                root = root.next;    
            }
            root = tempChild.next;
        }
    }
}

 

117. Populating Next Right Pointers in Each Node II

原文:https://www.cnblogs.com/MarkLeeBYR/p/10536166.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!