VISUALGO//PROBLEMS
single number · bit manipulationeasy
LeetCode #136
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