LeetCode:Bulb Switcher
1、题目名称 Bulb Switcher(灯泡开关) 2、题目地址 https://leetcode.com/problems/bulb-switcher/ 3、题目内容 英文: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 off if it's on). For the n th round, you only toggle the last bulb. Find how many bulbs are on after n rounds. 中文:现有n个灯泡,默认都是关闭的。第一轮会打开所有的灯泡,第二轮关闭所有偶数次序的灯泡,第三轮翻转所有次序为三的倍数位置的灯泡,直到第n轮拨动最后一个灯泡的开关。试确定第n轮后还有几盏灯是亮的。 4、解题方法1(TLE) 一开始我还是尝试着写了一段用于暴力破解问题的代码,这段代码毫无悬念地会导致TLE(Time Limit Exceeded)。 Java代码如下: /** * 灯泡开关测试 *