Loading...
Loading...
At a college fest, every student collects two wristbands with the same ID: one for entry and one for food. At the end of the day the volunteers scan all the returned wristbands. Exactly one student returned only one wristband.
Given the scanned IDs in any order, print the ID that appears only once.
Example 1
Input
5 4 1 2 1 2
Output
4
1 and 2 appear twice. 4 appears once.
Example 2
Input
1 7
Output
7
Only one wristband was scanned.
Try the problem first. Open one hint at a time.
Think about what x ^ x and x ^ 0 are for any number x.
XOR does not care about order: a ^ b ^ a is the same as a ^ a ^ b.
XOR all the IDs together. Each pair cancels to 0, and only the unpaired ID is left.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor