2023-09-20 16:50:56 +0000 UTC

Binary Number with Alternating Bits

Code

class Solution:
    def hasAlternatingBits(self, n: int) -> bool:
        return n & (n >> 1) == 0 and n & (n >> 2) == n >> 2