Straightforward Python 39ms


  • 0
    class Solution(object):
        def hasAlternatingBits(self, n):
            """
            :type n: int
            :rtype: bool
            """
            bin_form = bin(n)[2:]
            for i in range(1, len(bin_form)):
                if bin_form[i] == bin_form[i - 1]:
                    return False
            return True
    

Log in to reply
 

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