@@ -0,0 +1,874 @@
+/**%0A * Definition for binary tree with next pointer.%0A * public class TreeLinkNode %7B%0A *     int val;%0A *     TreeLinkNode left, right, next;%0A *     TreeLinkNode(int x) %7B val = x; %7D%0A * %7D%0A */%0Apublic class Solution %7B%0A    public void connect(TreeLinkNode root) %7B%0A        if(root == null %7C%7C root.left == null)%7B%0A            return;%0A        %7D%0A        TreeLinkNode upper = root;%0A        while(upper.left != null)%7B%0A            TreeLinkNode lowerHead = upper.left;%0A            TreeLinkNode lower = lowerHead;%0A            while(true)%7B%0A                lower.next = upper.right;%0A                if(upper.next != null)%7B%0A                    lower.next.next = upper.next.left;%0A                    lower = lower.next.next;%0A                    upper = upper.next;%0A                %7Delse%7B%0A                    break;%0A                %7D%0A            %7D%0A            upper = lowerHead;%0A        %7D%0A    %7D%0A%7D

Q116 Populating Next Right Pointers in Each Node