319. Bulb Switcher
来源:互联网 发布:网络剧受众分析 编辑:程序博客网 时间:2024/05/23 19:14
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.
【思路】从灯的转换得到要求n之内能开平方的个数,暴力遍历会超时。
class Solution {public: int bulbSwitch(int n) { int count = 0; for(int i = 1; i * i <=n ; i++) ++count; return count; }};
0 0
- 319. Bulb Switcher && 672. Bulb Switcher II
- [leetcode] 319. Bulb Switcher
- 319. Bulb Switcher
- leetcode 319. Bulb Switcher
- 319. Bulb Switcher LeetCode
- LeetCode 319. Bulb Switcher
- 319. Bulb Switcher
- 319. Bulb Switcher
- 319. Bulb Switcher
- LeetCode *** 319. Bulb Switcher
- [leetcode]319. Bulb Switcher
- 319. Bulb Switcher
- 319. Bulb Switcher
- leetcode-319. Bulb Switcher
- leetcode 319. Bulb Switcher
- 319. Bulb Switcher #Medium
- leetcode 319. Bulb Switcher
- 【leetcode】319. Bulb Switcher
- PCI Vendor and Device IDs
- 解决angular Js中出现unsafe:data:;base64,的问题
- lambda
- Backbone与Angular的比较
- 第一篇 SCI 综述被接收的感想
- 319. Bulb Switcher
- 【bzoj3916】【Baltic2014】【friends】【hash】
- StudyJams-第01课_初识Android的View(TextView、ImageView、Button)
- 数据结构算法——顺序表的应用
- LeetCode *** 236. Lowest Common Ancestor of a Binary Tree
- 26. Remove Duplicates from Sorted Array
- Date Range Picker 插件 bootstrap
- Matlab数字图像处理之图像运算
- Matlab 图像处理相关函数命令大全