# 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);
}

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

## LeetCode319——Bulb Switcher

• zhangxiao93
• 2015年12月21日 09:58
• 2195

## 319. Bulb Switcher

// CPP class Solution { public: int bulbSwitch(int n) { int result = 0; for (int...
• baidu_23318869
• 2015年12月23日 13:13
• 1847

## leetcode 672. Bulb Switcher II

There is a room with n lights which are turned on initially and 4 buttons on the wall. After perfor...
• huanghanqian
• 2017年09月05日 22:34
• 965

## [leetcode]319. Bulb Switcher

• zorelemn
• 2016年04月13日 20:53
• 127

## LeetCode *** 319. Bulb Switcher

• treeshy
• 2016年04月07日 08:17
• 81

## leetcode 319. Bulb Switcher

QuestionThere are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn of...
• StubbornAnt
• 2015年12月28日 09:56
• 253

## Bulb Switcher II问题及解法

672. Bulb Switcher II LeetCode
• u011809767
• 2017年09月13日 09:10
• 318

## [leetcode] 319. Bulb Switcher

There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every...
• TstsUgeg
• 2015年12月19日 19:47
• 127

## 319. Bulb Switcher && 672. Bulb Switcher II

There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every ...
• zjucor
• 2017年09月03日 13:23
• 825

## [Leetcode] 319. Bulb Switcher

• xinyuehuixin
• 2016年06月03日 10:33
• 140

举报原因： 您举报文章：319. Bulb Switcher 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)