N0319-Bulb Switcher
来源:互联网 发布:linux视频教程 百度云 编辑:程序博客网 时间:2024/05/16 09:16
- Problem Description
- Analyse
- Method one On
Problem Description
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.
Examples:
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.
Analyse
判断完全平方数
Method one: O(n)
JavaScript代码如下:
var bulbSwitch = function a(n) { if(n==0) return 0; var num = 0; for(var i=1;i<=n;i++){ var temp = Math.sqrt(i); if(temp == Math.floor(temp)) num++; } return num;};
0 0
- N0319-Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- Bulb Switcher
- 319. Bulb Switcher && 672. Bulb Switcher II
- [leetcode] 319. Bulb Switcher
- leetcode Bulb Switcher
- [Leetcode]Bulb Switcher
- 【Leetcode】Bulb Switcher
- leetcode 319 Bulb Switcher
- Bulb Switcher | LeetCode
- 优信二手车与时俱进,缔造创新发展典范
- 8583报文解析实例介绍
- 单目相机标定-原理及实现
- MYSQL GROUP_CONCAT 与REGEXP用法
- Hebb和Delta学习规则
- N0319-Bulb Switcher
- display和position的值与作用
- 算法训练 判定字符位置
- HDU 2544 最短路
- 数据库事务的四大特性以及事务的隔离级别
- Day 1
- A-B 字符串删除
- 深入理解JVM(3)
- 最后一公里——发布