Skip to main content
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

  • 1 <= n <= 2^31 - 1

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Last modified on September 7, 2026