Given a set of numbers where each number appears twice in the set except one number t, who only appears once. Now the task is to find out t.
Yes, if it is the first time you find the answer, you may probably scream out. The mechod is very simple, just use an operation: bitwise EXCLUSIVE OR, or XOR (^). Scan the set, keep doing XOR to the current number and previous result to get the new result, and the last result is the number t.
For example, suppose the set is: 1 5 2 1 2, then the result 1 XOR 5 XOR 2 XOR 1 XOR 2 = 5. Does it seem like a magic?