Press "Enter" to skip to content

Posts published in “Bit”

花花酱 LeetCode 693. Binary Number with Alternating Bits

Problem:

Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values.

Example 1:

Example 2:

Example 3:

Example 4:

 

Idea:

Bit operation

Solution

C++