A Simple Recursive Solution in Java (No Extra Space)


  • 0
    H
    public void connect(TreeLinkNode root) {
            if (root == null) {
                return;
            }
            if (root.left != null) {
                root.left.next = root.right;
                if (root.next != null) {
                    root.right.next = root.next.left;
                }
            }
            if (root.left != null) {
                this.connect(root.left);
            }
            if (root.right != null) {
                this.connect(root.right);
            }
        }

Log in to reply
 

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