Given a non-empty array of integers, every element appears twice except for one. Find that single one.
Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory?
This is an xor problem. If you have a list of number that are unsorted and you want to find the unique number, then xor all the numbers in the list and the final result will be the unique number. For example,
[2, 2, 1] is [010, 010, 001] so tracing through the code above:
or for [4, 1, 2, 1, 2]