LeetCode 693, Easy. Topics: Bit Manipulation. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:
Problem
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.
Examples
Constraints
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026