Bulb Switcher

Problem: Bulb Switcher

If a number n has even numbers of divisors, it will definitely be off since if it got on at i-th turn it will be turn off at n/i-th turn. However, if n is a square number, it will be turn on and not got off.

Code in Python:

class Solution(object):
    def bulbSwitch(self, n):
        """
        :type n: int
        :rtype: int
        """
        return int(math.sqrt(n))

results matching ""

    No results matching ""