Given a positive integer n, return true if its binary representation has alternating bits, such as 1010 or 0101. Pattern focus: Check kth Bit. Compare adjacent bits and ensure no two neighboring bits are equal.
n = positive integer
true if the binary representation has alternating bits
Example 1:
Input:
n = 5
Output:
true
Explanation:
5 is 101 in binary, which alternates.
Example 2:
Input:
n = 7
Output:
false
Explanation:
7 is 111 in binary, which has repeated bits.