Java solution with O(1) memory+ O(n) time
\n\n    public class Solution {\n        public void connect(TreeLinkNode root) {\n            TreeLinkNode level_start=root;\n            while(level_start!=nu
\n\n    public class Solution {\n        public void connect(TreeLinkNode root) {\n            TreeLinkNode level_start=root;\n            while(level_start!=null){\n                TreeLinkNode cur=level_start;\n                while(cur!=null){\n                    if(cur.left!=null) cur.left.next=cur.right;\n                    if(cur.right!=null && cur.next!=null) cur.right.next=cur.next.left;\n                    \n                    cur=cur.next;\n                }\n                level_start=level_start.left;\n            }\n        }\n    }
[]