leetcode之Bulb Switcher
来源:互联网 发布:单片机at 编辑:程序博客网 时间:2024/06/04 17:57
这题本身其实并不难。按照步骤做即可,但是根本步骤出来的答案让人显而易见的容易猜测一个事实就是这就是求其整数(平方根)。结果真的是。。。哪位数学大牛来帮忙证明下啊。跪求。
这个是根据步骤写的代码。然而超时了。。挂不得分类是数学和难题。。。
class Solution(object): def bulbSwitch(self, n): """ :type n: int :rtype: int """ import math return int(math.sqrt(n))
没错,这个代码通过了,就是求平方根的整数部分。
from collections import Counter def toggle(x): if x == 1: return 0 else: return 1 if n == 1: return 1 for i in range(n): if i == n - 1: print list1 list1[-1] = toggle(list1[-1]) print list1 a = Counter(list1) return a[1] if i == 0: list1 = [1] * n else: for j in range(n / (i + 1)): list1[(i + 1) * j + i] = toggle(list1[(i + 1) * j + i])
这个是根据步骤写的代码。然而超时了。。挂不得分类是数学和难题。。。
0 0
- leetcode之Bulb Switcher
- LeetCode 之 Bulb Switcher
- [leetcode] 319. Bulb Switcher
- leetcode Bulb Switcher
- [Leetcode]Bulb Switcher
- 【Leetcode】Bulb Switcher
- leetcode 319 Bulb Switcher
- Bulb Switcher | LeetCode
- Leetcode-319 Bulb Switcher
- Leetcode: Bulb Switcher
- leetcode 319. Bulb Switcher
- 【LEETCODE】319-Bulb Switcher
- LeetCode Bulb Switcher
- LeetCode Bulb Switcher
- Leetcode: Bulb Switcher
- leetcode笔记:Bulb Switcher
- LeetCode:Bulb Switcher
- 319. Bulb Switcher LeetCode
- 1209 - The MySQL server is running with the --read-only option so it cannot execute this statement
- 理论: 图论(6): 单源赋值图最短路径
- 使用hive访问elasticsearch的数据
- 一起talk C栗子吧(第八十六回:C语言实例--使用信号进行进程间通信三)
- 第1章 Python简介
- leetcode之Bulb Switcher
- 大文件下载(暂停和恢复下载)
- c语言实现普通队列
- ural 1005
- 最佳运动员搭配问题
- MyEclipse无法自动提示JUnit导包问题
- 《C++ STL基础 及应用》笔记
- 回首2015,展望2016
- Eclipse常用快捷键