If we xor all numbers, the number without a double will remain.
Time: , space:
.
class Solution:
def singleNumber(self, nums: List[int]) -> int:
single = 0
for x in nums:
single ^= x
return single
Leave a comment