Very simple Java accepted one variable solution


  • 0
    M
        public void connect(TreeLinkNode root) {
            if(root == null) {
                return;
            }
            
            TreeLinkNode curr = root;
            while(curr != null && curr.left != null) {
                curr.left.next = curr.right;
                if(curr.next != null) {
                    curr.right.next = curr.next.left;    
                }
                curr = curr.next;
            }
            // connect next level start from left most node
            connect(root.left);
        }
    

Log in to reply
 

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