bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 693. Binary Number with Alternating Bits

693. Binary Number with Alternating Bits

Leetcode Solutions

Bitwise Manipulation Approach

  1. Initialize cur to n & 1 to store the current bit.
  2. Right-shift n by one bit.
  3. Loop while n is greater than zero: a. If cur is equal to n & 1, return false because two adjacent bits are the same. b. Update cur to n & 1 (the new current bit). c. Right-shift n by one bit.
  4. If the loop completes without returning false, return true.
UML Thumbnail

Convert to Binary String Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...