The insight: XOR all the numbers together. Every number that appears twice will cancel itself out (). What remains is the unique number.
For : compute . Since XOR is commutative, rearrange: .
This works because XOR has the self-canceling property and the identity element is 0.