1 Star 0 Fork 0

wd6/LeetCode-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bulb-switcher.py 866 Bytes
一键复制 编辑 原始数据 按行查看 历史
kamyu 提交于 9年前 . Update bulb-switcher.py
# Time: O(1)
# Space: O(1)
# 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 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.
class Solution(object):
def bulbSwitch(self, n):
"""
type n: int
rtype: int
"""
# The number of full squares.
return int(math.sqrt(n))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wd6/LeetCode-1.git
git@gitee.com:wd6/LeetCode-1.git
wd6
LeetCode-1
LeetCode-1
master

搜索帮助