My Python Solution

  • 1
    import math
    class Solution(object):
        def getFactors(self, n):
            return self.solve([], n, [], 2)
        def solve(self, ret, n, sofar, start):
            if sofar:
                ret.append(sofar + [n])
            for i in range(start, int(math.sqrt(n))+1):
                if n % i == 0:
                    self.solve(ret, n/i, sofar+[i], i)
            return ret

  • 0

    math.floor is not necessary.

  • 0

    you're right, I previously used ceil and forget to remove it

Log in to reply

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