@@ -0,0 +1,1818 @@
+public class Solution %7B%0A    public void connect(TreeLinkNode root) %7B%0A        if (root == null) %7B%0A            return;%0A        %7D%0A        %0A        TreeLinkNode parent = root;%0A        %0A        // check initial node at current level is valid or not.%0A        while (parent != null) %7B%0A            TreeLinkNode nextLevel = null;%0A            TreeLinkNode left = null;%0A            %0A            // iterate over current level.            %0A            while (parent != null) %7B%0A                if (parent.left != null) %7B%0A                    // if parent is the first node at this level, left should be null,%0A                    // no nodes to be connected, and nextLevel should be parent.left%0A                    if (left == null) %7B%0A                        nextLevel = parent.left;%0A                    %7D else %7B%0A                        // if left!=null, means parent is not the first node at this level,%0A                        // left is left/right node of previous sibling of parent.%0A                        left.next = parent.left;%0A                    %7D%0A                    left = parent.left;%0A                %7D%0A                %0A                if (parent.right != null) %7B%0A                    // if parent is the first node at this level and has no left child, %0A                    // right child should be set as the nextLevel.%0A                    if (left == null) %7B%0A                        nextLevel = parent.right;%0A                    %7D else %7B%0A                        // if parent has left child, or parent has no left child but is not %0A                        // the first node at this level.%0A                        left.next = parent.right;%0A                    %7D%0A                    left = parent.right;%0A                %7D%0A                parent = parent.next;%0A            %7D%0A            parent = nextLevel;%0A        %7D%0A    %7D%0A%7D

add populating next right pointers in each node ii solution