Practice Binary Number with Alternating Bits
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Source: Binary Number with Alternating Bits on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
n = 5
Output
true
# Example 2
Input
n = 7
Output
false
# Example 3
Input
n = 11
Output
false
Constraints
1 <= n <= 2^31 - 1
Related LeetCode Problems
Practice more problems similar to Binary Number with Alternating Bits.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.