given an array of integers every element appears three times except for one which appears exactly once find that single one note your algorithm should have a linear runtime complexity could you implement it without using extra memory solution 32 bits for each integer consider 1 bit in it the sum of each integer s corresponding bit except for the single number should be 0 if mod by 3 hence we sum the bits of all integers and mod by 3 the remaining should be the exact bit of the single number in this way you get the 32 bits of the single number another awesome answer another awesome answer
def single_number2(nums):
    ones, twos = 0, 0
    for i in range(len(nums)):
        ones = (ones ^ nums[i]) & ~twos
        twos = (twos ^ nums[i]) & ~ones
    return ones