Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e7be8cf

Browse files
Update 507._Perfect_Number.md
1 parent 102dd17 commit e7be8cf

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎docs/Leetcode_Solutions/507._Perfect_Number.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ Note: The input number n will not exceed 100,000,000. (1e8)
2626
> 思路 1
2727
******- 时间复杂度: O(lgN)******- 空间复杂度: O(1)******
2828

29-
用了一个比较巧妙的方法,首先排除一些corner case,num小于等于1的时候直接返回False
29+
用了一个比较巧妙的方法,首先排除一些 corner case,num 小于等于1的时候直接返回 False
3030

31-
然后后面开始这个方法,就是我们其实不需要对所有小于num的数字做遍历,只需要从2遍历到int(sqrt(num))即可,
32-
然后每次可以整除的时候都加上当前数字i和num//i,然后初始化的时候让sums=1,这样最后就是不包含自己的所有因子的和,最后return sum == num
31+
然后后面开始这个方法,就是我们其实不需要对所有小于 num 的数字做遍历,只需要从 2 遍历到 int(sqrt(num))即可,
32+
然后每次可以整除的时候都加上当前数字 i 和 num//i,然后初始化的时候让 sums = 1 ,这样最后就是不包含自己的所有因子的和,最后 return sum == num
3333

34+
35+
beats 95.73%
3436
```python
3537
from math import sqrt
3638
class Solution(object):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /