https://leetcode.com/problems/bulb-switcher/#/descriptionarrow-up-right
https://discuss.leetcode.com/topic/39558/share-my-o-1-solution-with-explanationarrow-up-right
这道题就是脑筋急转弯。
简单讲,就是找小于 n 的完全平方数的个数(因为他们的 factor 的个数是奇数)
而这样又直接等于 n 开方
public class Solution { public int bulbSwitch(int n) { return (int) Math.sqrt(n); } }
Last updated 6 years ago