Simple python solution


  • 0
    Z
    class Solution(object):
        def getFactors(self, n):
            """
            :type n: int
            :rtype: List[List[int]]
            """
            if n==1:
                return []
            ret = []
            def helper(n,index,path):
                if n<index:
                    return
                for i in range(index,int(math.sqrt(n))+1):
                    if n%i == 0:
                        ret.append(path+[i,n//i])
                        helper(n//i,i,path+[i])
            helper(n,2,[])
            return ret

Log in to reply
 

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