given a positive integer check whether it has alternating bits namely if two adjacent bits will always have different values for example input 5 output true because the binary representation of 5 is 101 input 7 output false because the binary representation of 7 is 111 input 11 output false because the binary representation of 11 is 1011 input 10 output true because the binary representation of 10 is 1010 time complexity onumber of bits in n time complexity o1 time complexity o number of bits in n time complexity o 1 for bits ending with zero 1010 for bits ending with one 0101
def has_alternative_bit(n):
    first_bit = 0
    second_bit = 0
    while n:
        first_bit = n & 1
        if n >> 1:
            second_bit = (n >> 1) & 1
            if not first_bit ^ second_bit:
                return False
        else:
            return True
        n = n >> 1
    return True    


def has_alternative_bit_fast(n):
    mask1 = int('aaaaaaaa', 16)  
    mask2 = int('55555555', 16)  
    return mask1 == (n + (n ^ mask1)) or mask2 == (n + (n ^ mask2))