276. Every element appears an even number of times except one that appears an odd number of times. Find it.
EasySearching & selection
Technical
Show model answer
XOR all elements. XOR is associative and commutative, and x ⊕ x = 0, so every pair cancels and the odd-occurrence element remains. O(n) time and O(1) space, versus O(n) space for a hash map of counts.