Problem: All appear twice except two numbers. Find both.
XOR all →
Find set bit (differs between , )
Partition by that bit, XOR each group
xorAll = XOR of all nums
diffBit = xorAll & (-xorAll)
a = b = 0
for num in nums:
if num & diffBit: a ^= num
else: b ^= num
return [a, b]
Numbers with same bit cancel in each partition.
Time: . Space: .