Tap here to switch tabs
Problem
Submissions

Problem: Binary Number with Alternating Bits

Binary Number with Alternating Bits asks whether a positive integer's binary representation has adjacent bits that always differ, returning true or false.

Statement

Given a positive integer n, determine whether its binary representation has alternating bits. Return true if adjacent bits always have different values, and false otherwise.

Constraints:

  • 1≤1 \leq n ≤231−1\leq 2^{31} - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Binary Number with Alternating Bits

Binary Number with Alternating Bits asks whether a positive integer's binary representation has adjacent bits that always differ, returning true or false.

Statement

Given a positive integer n, determine whether its binary representation has alternating bits. Return true if adjacent bits always have different values, and false otherwise.

Constraints:

  • 1≤1 \leq n ≤231−1\leq 2^{31} - 1