bulb专题

LeetCode //C - 319. Bulb Switcher

319. Bulb Switcher There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s

LeetCode---Bulb Switcher解题分析

题意描述:给定n个灯泡,初始化全为off,第一趟全问部on,第二趟将每第二个off,第三趟将每第三个反转……第n趟将第n个反转,最后返回灯泡处于on的数目。给定n=3,则有以下过程: 开始时,3个灯泡[off, off, off];第一轮,3个灯泡[on, on, on];第二轮,3个灯泡[on, off, on];第三轮,3个灯泡[on, off, off]。所以最后返回1 解题思路一:该方

leetcode-319. Bulb Switcher

There are n bulbs that are initially off. You first turn on all >the bulbs. Then, you turn off every second bulb. On the >third round, you toggle every third bulb (turning on if it’s >off or turning

LeetCode 319 Bulb Switcher(灯泡切换)(从规律中发现算法……)

翻译 这儿有n个灯泡被初始化。首先,你点亮所有的灯泡。然后,你关掉每第二个灯泡。在第三回,你切换每第三个灯泡(如果它是关闭的则开启它,如果它是开启的则关闭它)。对于第i回,你切换每第i个灯泡。对于第n回,你仅仅切换最后一个灯泡。找出在n回之后还有多少个灯泡是亮着的。 原文 There are n bulbs that are initially off. You first turn on

leetcode - 319. Bulb Switcher

Description There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or

leetcode - 319. Bulb Switcher

Description There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or