[
math
]
Leetcode 0319 Bulb Switcher
Problem statement
https://leetcode.com/problems/bulb-switcher/
Solution
Classical math brainteaser, where we need to check number of divisors for each number and bulb will be on in the end, if number of divisors is odd. Only squares have odd number of divisors, so the answer is int(sqrt(n))
.
Complexity
It is O(1)
for time and space
Code
class Solution:
def bulbSwitch(self, n):
return int(sqrt(n))