<reponame>Ravan339/LeetCode<filename>Python/binary-number-with-alternating-bits.py
# https://leetcode.com/problems/binary-number-with-alternating-bits/


class Solution:
    def hasAlternatingBits(self, n):
        """
        :type n: int
        :rtype: bool
        """
        prev_bit = -1

        while n > 0:
            cur_bit = n & 1
            if cur_bit == prev_bit: return False
            prev_bit = cur_bit
            n >>= 1

        return True

# https://leetcode.com/problems/binary-number-with-alternating-bits/


class Solution:
    def hasAlternatingBits(self, n):
        """
        :type n: int
        :rtype: bool
        """
        prev_bit = -1

        while n > 0:
            cur_bit = n & 1
            if cur_bit == prev_bit: return False
            prev_bit = cur_bit
            n >>= 1

        return True
# https://leetcode.com/problems/binary-number-with-alternating-bits/ :type n: int         :rtype: bool