[LeetCode] 507. Perfect Number
Python
class Solution:
def checkPerfectNumber(self, num: int) -> bool:
if num < 2:
return False
answer = 1
for i in range(2, int(math.sqrt(num) + 1)):
if num % i == 0:
answer = answer + i + num / i
return num == answer
댓글남기기