Simple Python solution


  • 0
    class Solution:
        def hasAlternatingBits(self, n):
            if not n:
                return False
            num = n ^ (n >> 1)
            return not (num & (num + 1))
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.