Posted on 2023-04-27 21:49
Uriel 閱讀(37)
評論(0) 編輯 收藏 引用 所屬分類:
數學 、
閑來無事重切Leet Code
有n個燈泡,開始全部點亮,然后一次關閉/電量2的倍數、3的倍數...n的倍數,問最后剩下幾個燈
看了Discussion才明白->https://leetcode.com/problems/bulb-switcher/solutions/3459201
1 #319
2 #Runtime: 17 ms (Beats 49.15%)
3 #Memory: 13.2 MB (Beats 91.53%)
4
5 class Solution(object):
6 def bulbSwitch(self, n):
7 """
8 :type n: int
9 :rtype: int
10 """
11 return int(sqrt(n))