Python easy


  • 0
    L
    from math import sqrt
    class Solution(object):
        def checkPerfectNumber(self, num):
            """
            :type num: int
            :rtype: bool
            """
            ret=[1]
            for i in xrange(2,int(math.sqrt(abs(num))+1)):
                if num%i==0:
                    ret.append(i)
                    ret.append(num/i)
            return sum(ret)==abs(num) if num!=1 else False

Log in to reply
 

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