He bought an entire bottle of ink in preparation and practically put himself under house arrest for months, using a most peculiar anti-escape technique:

Hugo locked away his clothes to avoid any temptation of going outside and was left with nothing to wear except a large gray shawl. He had purchased the knitted outfit, which reached right down to his toes, just for the occasion. It served as his uniform for many months.

Whatever he did, it seemed to work.

He finished the book weeks before the deadline, using up the whole bottle of ink to write it.