Duplicate like a weapon, arrays like heaven
@tim suggested a way to do this with less memory by sorting the array. There's another way to do it with less memory without needing to sort.

Let's say that \$k\$ is the duplicate value in the array. Then we know that the sum of the elements in the array is equal to

\begin{align}
0 + 1 + 2 + 3 + \cdots + (n - 2) + k = \frac{(n - 2)(n - 1)}{2} + k,
\end{align}

where we're using the identity

\begin{align}
1 + 2 + 3 + \cdots + n = \frac{n (n + 1)}{2}.
\end{align}

So if sum is the sum of the values in the array, the duplicate value will be sum - (n - 2) * (n - 1) / 2.