它的意思是我的時(shí)間複雜度 = O(n^2)
但實(shí)際上可以用 O(sqrt(n)) 就好了
class Solution(object): def bulbSwitch(self, n): x = [] total = 0 for _ in range(n): x.append(False) for i in range(1, n + 1): for j in range(1, n + 1): if j % i == 0: x[j - 1] = not x[j - 1] for i in range(n): if x[i] == True: total += 1 return total |
class Solution(object): def bulbSwitch(self, n): return int(n**0.5) |
好喔