mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			886 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			886 B
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>给定一个正整数 <code>n</code> ,请你统计在 <code>[0, n]</code> 范围的非负整数中,有多少个整数的二进制表示中不存在 <strong>连续的 1 </strong>。</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 | 
						|
<p><strong>示例 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>输入:</strong> n = 5
 | 
						|
<strong>输出:</strong> 5
 | 
						|
<strong>解释:</strong> 
 | 
						|
下面列出范围在 [0, 5] 的非负整数与其对应的二进制表示:
 | 
						|
0 : 0
 | 
						|
1 : 1
 | 
						|
2 : 10
 | 
						|
3 : 11
 | 
						|
4 : 100
 | 
						|
5 : 101
 | 
						|
其中,只有整数 3 违反规则(有两个连续的 1 ),其他 5 个满足规则。</pre>
 | 
						|
 | 
						|
<p><strong>示例 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>输入:</strong> n = 1
 | 
						|
<strong>输出:</strong> 2
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong>示例 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>输入:</strong> n = 2
 | 
						|
<strong>输出:</strong> 3
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
 | 
						|
<p><strong>提示:</strong></p>
 | 
						|
 | 
						|
<ul>
 | 
						|
	<li><code>1 <= n <= 10<sup>9</sup></code></li>
 | 
						|
</ul>
 |