Close
Close

Please explain this solution Given a number N, find all factors of N. Example: N = 6 factors = {1, 2, 3, 6} Make sure the returned array is

   Akhand_pratap

class Solution:    # @param A : integer    # @return a list of integers    def allFactors(self, A):        factors = list()        if A == 0 or A == 1:            factors.append(A)            return factors        upperbound = int(math.sqrt(A)) + 1        for i in range(1, upperbound):            if A % i == 0:                factors.append(i)                factors.append(int(A / i))        factors=list(set(factors))        factors.sort()        return factors


Answers

Ask Yours
Post Yours
Write your answer