Super easy Python recursive solution


  • 0
    M
    class Solution(object):
        def getFactors(self, n):
    
            rt=self.helper(n);
            rt.remove([n]);
            return rt;
            
        def helper(self,n):
            rt=[[n]];
            
            for i in range(2,int(n**0.5)+1):
                if n%i==0:
                    for l in self.helper(n/i):
                        if l[0]>=i:
                            rt.append([i]+l);
            
            return rt;
    

    Get all the breakup factors in ascending order and remove the number itself in the final result.


Log in to reply
 

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