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