Binary Number with Alternating Bits Description link Solution bin in python Code O(1) class Solution: def hasAlternatingBits(self, n: int) -> bool: return '00' not in bin(n) and '11' not in bin(n)