Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

Only bulbs with index equaling a perfect square number will be on in the end. (because it has an odd number of divisors). So a simple solution follows:

public static int bulbSwitch(int n) { return (int)Math.sqrt((double)n); }

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.