forked from gzwl/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
简单分析一下就可以看出,一个灯能不能被熄灭就看它的因数个数是不是奇数 | ||
比如说10,那么第1、2、5、10趟时它会受影响,所以最终是灭的 | ||
然后9,那么第1、3、9趟时它会受影响,所以最终是亮的 | ||
那么什么时候一个数的因数个数是奇数呢,当它是完全平方数的时候 | ||
所以答案就是1~n的完全平方数的个数 | ||
*/ | ||
|
||
class Solution { | ||
public: | ||
int bulbSwitch(int n) { | ||
return sqrt(n); | ||
} | ||
}; |