Tap here to switch tabs
Problem
Submissions

Problem: Binary Number with Alternating Bits

med
30 min
Try to solve the Binary Number with Alternating Bits problem.

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

med
30 min
Try to solve the Binary Number with Alternating Bits problem.

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