【Leetcode】Binary Number with Alternating Bits

class Solution(object):

    def hasAlternatingBits(self, n):

        """

        :type n: int

        :rtype: bool

        """

        s = bin(n)

        return '00' not in s and '11' not in s

1 bin(a)就是得到一个string

2 alternating bits就是说没有连续的‘00’,也没有连续的‘11’

你可能感兴趣的:(【Leetcode】Binary Number with Alternating Bits)