All Patterns
Pattern 18
Bitwise XOR
XOR is its own inverse: a ^ a = 0 and a ^ 0 = a. XOR-ing all elements cancels duplicates, leaving only the unique ones.
Time
O(n)
Space
O(1)
Recognize it when
- Find the single number that appears once
- Find two numbers appearing an odd number of times
- Missing number in range
Progress0/3
0 solved0 attempted
Questions — ordered by difficulty
#136Easy
Single Number
Every element appears twice except one. Find that single element using O(1) space.
arraybit-manipulation
#260Medium
Single Number III
Two elements appear once, all others appear twice. Find those two elements.
arraybit-manipulation
#268Easy
Missing Number (XOR approach)
Given an array nums containing n distinct numbers in the range [0, n], find and return the one number in that range that is missing. Same as LC 268 but focusing specifically on the XOR bit-manipulation approach rather than the math approach.
arraybit-manipulationmath