Accepted Java solution


  • 0
    A
        public void connect(TreeLinkNode root) {
            if(root == null) {
                return;
            }
    
            TreeLinkNode current = root, leftMost = root.left;
    
            while(leftMost != null) {
                current.left.next = current.right;
                if(current.next == null) {
                    current = leftMost;
                    leftMost = current.left;
                } else {
                    current.right.next = current.next.left;
                    current = current.next;
                }
            }
        }
    

Log in to reply
 

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