VISUALGO//PROBLEMS
single number · bit manipulationeasy
num
·
xor
·
nums
·
·
·
num
·
·
·
·
·
xor
·
·
·
·
·
ELEMENTS
nums
Python
def singleNumber(nums: list[int]) -> int:
xor = 0
for num in nums:
xor ^= num # pairs cancel: x ^ x = 0
return xor