Skip to content

Practice Non-negative Integers without Consecutive Ones

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#600
LeetCode Problem

Non-negative Integers without Consecutive Ones

Problem Statement

Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.

Source: Non-negative Integers without Consecutive Ones on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 5
Output
5

# Example 2

Input
n = 1
Output
2

# Example 3

Input
n = 2
Output
3

Constraints

1 <= n <= 10^9

Related LeetCode Problems

Practice more problems similar to Non-negative Integers without Consecutive Ones.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.