mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-13 19:31:42 +08:00
add leetcode problem-cn part6
This commit is contained in:
45
算法题(国内版)/problem (Chinese)/灯泡开关 [bulb-switcher].html
Normal file
45
算法题(国内版)/problem (Chinese)/灯泡开关 [bulb-switcher].html
Normal file
@@ -0,0 +1,45 @@
|
||||
<p>初始时有 <code>n</code><em> </em>个灯泡处于关闭状态。第一轮,你将会打开所有灯泡。接下来的第二轮,你将会每两个灯泡关闭第二个。</p>
|
||||
|
||||
<p>第三轮,你每三个灯泡就切换第三个灯泡的开关(即,打开变关闭,关闭变打开)。第 <code>i</code> 轮,你每 <code>i</code> 个灯泡就切换第 <code>i</code> 个灯泡的开关。直到第 <code>n</code> 轮,你只需要切换最后一个灯泡的开关。</p>
|
||||
|
||||
<p>找出并返回 <code>n</code><em> </em>轮后有多少个亮着的灯泡。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/11/05/bulb.jpg" style="width: 421px; height: 321px;" /></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n =<strong> </strong>3
|
||||
<strong>输出:</strong>1
|
||||
<strong>解释:</strong>
|
||||
初始时, 灯泡状态 <strong>[关闭, 关闭, 关闭]</strong>.
|
||||
第一轮后, 灯泡状态 <strong>[开启, 开启, 开启]</strong>.
|
||||
第二轮后, 灯泡状态 <strong>[开启, 关闭, 开启]</strong>.
|
||||
第三轮后, 灯泡状态 <strong>[开启, 关闭, 关闭]</strong>.
|
||||
|
||||
你应该返回 1,因为只有一个灯泡还亮着。
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 0
|
||||
<strong>输出:</strong>0
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 3:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>n = 1
|
||||
<strong>输出:</strong>1
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= n <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
Reference in New Issue
Block a user