Talentd/FleetCode/Problems/

3950. Exactly One Consecutive Set Bits Pair

Easy
Read SolutionWatch Video

3950. Exactly One Consecutive Set Bits Pair

Easy51.0% Acceptance

You are given an integer n.

Return true if its binary representation contains exactly one pair of consecutive set bits, and false otherwise.

Example 1:

Input: nums = 6

Output: true

Explanation:

  • Binary representation of 6 is 110.
  • There is exactly one pair of consecutive set bits ("11"). Thus, the answer is true​​​​​​​.

Example 2:

Input: nums = 5

Output: false

Explanation:

  • Binary representation of 5 is 101.
  • There are no consecutive set bits. Thus, the answer is false​​​​​​​.

Constraints:

  • 0 <= n <= 105

Loading editor...

6