[LeetCode] Non-negative Integers without Consecutive Ones 非负整数不包括连续的1

Posted Grandyang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] Non-negative Integers without Consecutive Ones 非负整数不包括连续的1相关的知识,希望对你有一定的参考价值。

 

Given a positive integer n, find the number of non-negative integers less than or equal to n, whose binary representations do NOT contain consecutive ones.

Example 1:

Input: 5
Output: 5
Explanation: 
Here are the non-negative integers <= 5 with their corresponding binary representations:
0 : 0
1 : 1
2 : 10
3 : 11
4 : 100
5 : 101
Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 

 

Note: 1 <= n <= 109

 

s

 

以上是关于[LeetCode] Non-negative Integers without Consecutive Ones 非负整数不包括连续的1的主要内容,如果未能解决你的问题,请参考以下文章

[LeetCode] Non-negative Integers without Consecutive Ones 非负整数不包括连续的1

Non-negative Integers without Consecutive Ones

Leetcode 224: Basic Calculator

Basic Calculator II Leetcode

leetcode: Continuous Subarray Sum

leetcode 523. Continuous Subarray Sum