Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Single Number
Bookmark
Input
Example 1
Example 2
Example 3
Example 4
Custom
nums
=
[2, 2, 1]
0
1
2
2
2
1
0
1
2
2
2
1
0
1
2
2
2
1
i
result
0
0
0
0
= 0
0
1
2
2
2
1
i
result
0
0
0
0
= 0
^ nums[0]
0
0
1
0
= 2
0
1
2
2
2
1
i
result
0
0
0
0
= 0
^ nums[0]
0
0
1
0
= 2
result
0
0
1
0
= 2
0
1
2
2
2
1
i
result
0
0
1
0
= 2
^ nums[1]
0
0
1
0
= 2
0
1
2
2
2
1
i
result
0
0
1
0
= 2
^ nums[1]
0
0
1
0
= 2
result
0
0
0
0
= 0
0
1
2
2
2
1
i
result
0
0
0
0
= 0
^ nums[2]
0
0
0
1
= 1
0
1
2
2
2
1
i
result
0
0
0
0
= 0
^ nums[2]
0
0
0
1
= 1
result
0
0
0
1
= 1
0
1
2
2
2
1
single number = 1
algo
master
.
io
Step:
Every number appears twice except one. XOR all numbers: pairs cancel to 0, leaving the single number
0 / 8
Input
Example 1
Example 2
Example 3
Example 4
Custom
nums
=
[2, 2, 1]
0 / 8
algo
master
.
io
Step:
Every number appears twice except one. XOR all numbers: pairs cancel to 0, leaving the single number