Java concise O(1) space iterative solution


  • 1
    L
    public void connect(TreeLinkNode root) {
        while(root != null && root.left != null){
            TreeLinkNode cur = root;
            while(cur != null){
                cur.left.next = cur.right;
                if(cur.next != null) cur.right.next = cur.next.left;
                cur = cur.next;
            }
            root = root.left;
        }
    }

Log in to reply
 

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