# 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 off if it's on). For the ith round, you toggle every i bulb. For the nth round, you only toggle the last bulb.Find how many bulbs are on after n rounds.

Example:

Given n = 3.

At first, the three bulbs are [off, off, off].
After first round, the three bulbs are [on, on, on].
After second round, the three bulbs are [on, off, on].
After third round, the three bulbs are [on, off, off].

So you should return 1, because there is only one bulb is on.

public static int bulbSwitch(int n) {
return (int)(n >= 0 ? Math.sqrt(n) : 0);
}

• 本文已收录于以下专栏：

## leetcode 319 Bulb Switcher

leetcode319 Bulb Switcher题目描述 There are n bulbs that are initially off. You first turn on all the ...

## Leetcode 319. Bulb Switcher

Bulb Switcher好久没更新博客啦，主要是因为都没刷到什么好题，这一篇也是大大的水题，不过因为思考的过程种发生了种种有(yu)趣(chun)的故事，姑且把它当作一篇娱乐向的博文来写233 不...

## 319. Bulb Switcher

319. Bulb Switcher

## LeetCode 319. Bulb Switcher 解题报告

LeetCode 319. Bulb Switcher 解题报告

## LeetCode #319 - Bulb Switcher - Medium

ProblemThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn of...

## <LeetCode OJ> 319. Bulb Switcher

Total Accepted: 20000 Total Submissions: 48830 Difficulty: Medium There are n bulbs that are in...

## [Leetcode] 319. Bulb Switcher 解题报告

举报原因： 您举报文章：深度学习：神经网络中的前向传播和反向传播算法推导 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)