319. Bulb Switcher LeetCode
来源:互联网 发布:什么听歌识曲软件好 编辑:程序博客网 时间:2024/05/23 19:22
题意:有n盏灯,等一开始是灭的,然后拉下包含因子1的灯的开关,拉下包含因子2的灯的开关。。。拉下包含因子n的灯的开关。问最后有多少盏灯亮着。
题解:你会发现如果一个数不能开根号,那么它被打开的次数一定是偶数次,比如6,被1,2,3,6开。但是如果是一个能开根号的数,比如9,那么它被打开的次数一定是奇数,被1,3,9开。被开奇数次的等是亮着的。因此我们只需要判断1-n里面有多少个能开根号的数就可以了,是多少呢,就是sqrt(n);
class Solution {public: int bulbSwitch(int n) { return (int)sqrt(n); }};
0 0
- [leetcode] 319. Bulb Switcher
- leetcode 319. Bulb Switcher
- 319. Bulb Switcher LeetCode
- LeetCode 319. Bulb Switcher
- LeetCode *** 319. Bulb Switcher
- [leetcode]319. Bulb Switcher
- leetcode-319. Bulb Switcher
- leetcode 319. Bulb Switcher
- leetcode 319. Bulb Switcher
- 【leetcode】319. Bulb Switcher
- [Leetcode] 319. Bulb Switcher
- LeetCode-319.Bulb Switcher
- Leetcode 319. Bulb Switcher
- 【LeetCode】319. Bulb Switcher
- [leetcode] 319.Bulb Switcher
- 【leetcode】319. Bulb Switcher
- [leetcode] 319. Bulb Switcher
- [LeetCode]319. Bulb Switcher
- csdn博客积分规则
- 使用Intent和IntentFilter进行通信
- 【VB6】VB6类库项目中的Persistable
- 第一行代码-5.4 使用本地广播
- javaweb入门笔记(1)-Tomcat
- 319. Bulb Switcher LeetCode
- Cursor
- javaweb入门笔记(2)-http入门
- 模拟问题之密码学
- Educational Codeforces Round 7
- poj2430 2010.7.31
- javaweb入门笔记(3)-Servlet
- 268. Missing Number LeetCode
- poj1088 2010.7.31