Single Number
easyFind the element that appears only once when all others appear twice using XOR
Single Number
Key Insight
XOR all elements. Pairs cancel (a^a=0), single remains (a^0=a).
Step 1XOR Property
XOR
5
5
=0
0
0
0
0
1
0
1
^
5
5
=0
0
0
0
0
1
0
1
result
0
=0
0
0
0
0
0
0
0
76543210
5 ^ 5 = 0
a ^ a = 0 (same numbers cancel)
1 / 5