Slide 62
Slide 62 text
Odd Duck – Solutions
1. For each number in the array, count the occurrences of
that number and check if it's odd. Bad choice: O(n2)
2. Use a 2nd array to count the occurrences of each
number, then look in that 2nd array for the odd count.
3. Sort the array, and then look for the first occurrence of
a number that exists an odd number of times. (Bonus
points: look in pairs)
4. Use a 2nd array. When you encounter a number, add it
to the 2nd array (as the key). When you encounter it
again, remove/unset it.