Write a Python function to find the single element in a list where every element appears three times except for one.


Topic: Write a Python function to find the single element in a list where every element appears three times except for one.

Solution

def single_number(arr):
    ones, twos = 0, 0
    for x in arr:
        ones, twos = (ones ^ x) & ~twos, (ones & x) | (twos & ~x)
    assert twos == 0
    return ones



List all Python Programs