XOR has a special property: and . If you XOR all numbers together, pairs cancel out (become 0), leaving only the single number.
Example: . Example: .
XOR is commutative and associative, so order doesn't matter. You can XOR all elements in one pass, using space.