【LeetCode】319. Bulb Switcher
2016-06-19 16:19
281 查看
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:
Subscribe to see which companies asked this question
class Solution {
public:
int bulbSwitch(int n) {
return sqrt(n);
}
};
思路心得:
完全是写出来总结出的规律...
待证明
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.
Subscribe to see which companies asked this question
class Solution {
public:
int bulbSwitch(int n) {
return sqrt(n);
}
};
思路心得:
完全是写出来总结出的规律...
待证明
相关文章推荐
- 《剑指offer》:[41]数组中和为S的两个数
- Javascript面向对象编程(二):构造函数的继承
- MySQL导出导入数据命令
- 开发手机应用市场-DayOne补充
- zookeeper java客户端简单API
- [Java] 类的初始化步骤
- java JNDI路劲配置
- ITERATE 语句
- SQL的主键和外键约束
- MySQL命令行导出数据库
- QT 静态编译
- HDU 2571 命运
- ubuntu14.04 rsync配置
- 面向对象3
- Javascript 面向对象编程(一):封装
- java 成神之路 (二)
- postgresql----数据库表约束----PRIMARY KEY
- 0619学习进度条
- ppp数据帧的格式
- React Native es6继承(Component例子)