Easy to understand Java solution


  • 0
    Z
    public void connect(TreeLinkNode root) {
        if(root == null) return;
        TreeLinkNode parent = root;
        TreeLinkNode child1 = parent.left;
        TreeLinkNode child2 = parent.right;
        if(child1 != null) child1.next = child2;
        if(child2 != null) child2.next = (parent.next != null) ? parent.next.left:null;
        connect(root.left);
        connect(root.right);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.