> For the complete documentation index, see [llms.txt](https://liuyang89116.gitbook.io/my-leetcode-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liuyang89116.gitbook.io/my-leetcode-book/post_chapter_2_math/problem-319-bulb-switcher.md).

# Problem 319: Bulb Switcher

> <https://leetcode.com/problems/bulb-switcher/#/description>

## 思路

> <https://discuss.leetcode.com/topic/39558/share-my-o-1-solution-with-explanation>

这道题就是脑筋急转弯。

* 简单讲，就是找小于 n 的完全平方数的个数（因为他们的 factor 的个数是奇数）
* 而这样又直接等于 n 开方

```java
public class Solution {
    public int bulbSwitch(int n) {
        return (int) Math.sqrt(n);
    }
}
```
