600. Non-negative Integers without Consecutive Ones

来源:互联网 发布:他改变了中国淘宝评论 编辑:程序博客网 时间:2024/06/05 08:11

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: 5Output: 5Explanation: Here are the non-negative integers <= 5 with their corresponding binary representations:0 : 01 : 12 : 103 : 114 : 1005 : 101Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 

Note: 1 <= n <= 109

阅读全文
0 0
原创粉丝点击