class Solution:
def hasAlternatingBits(self, n):
"""
:type n: int
:rtype: bool
"""
bits = bin(n)
for i in range(len(bits)-1):
if bits[i] == bits[i+1]:
return False
return True
No comments:
Post a Comment