XOR all elements together.
def singleNumber(nums): result = 0 for num in nums: result ^= num return result
time, space.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
The approach
XOR all elements together.
def singleNumber(nums): result = 0 for num in nums: result ^= num return result
time, space.