Skip to main content

One post tagged with "Brainteaser"

View All Tags

ยท One min read
from math import isqrt


class Solution:
def bulbSwitch(self, n: int) -> int:
'''
-> find the amount number of intergers that have odd number of factors
-> only the square numbers have odd number of factors
-> find the max number that number's square <= n
'''
for i in range(n):
if (i + 1) ** 2 > n:
return i
return n


class Solution0:
def bulbSwitch(self, n: int) -> int:
return int(n**0.5)


class Solution2:
def bulbSwitch(self, n: int) -> int:
return isqrt(n)