Simple Python Solution


  • 0
    Y
    class Solution(object):
        def checkPerfectNumber(self, num):
            """
            :type num: int
            :rtype: bool
            """
            if num <= 1:
                return False
            cum = cur = 1
            while cur < int(math.sqrt(num)):
                cur += 1
                if num % cur == 0:
                    cum += cur + num / cur
            return num == cum
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.