Python easy standard backtracking


  • 0
    W
    def getFactors(self, n):
        ret = []
        self.dfs(n, [], ret)
        return ret
    
    def dfs(self, left, cur, ret):
        if cur and cur == sorted(cur):
            ret.append(cur +[left])
        for i in range(2, int(left**0.5)+1):
            if left % i == 0:
                cur.append(i)
                self.dfs(left // i, cur, ret)
                cur.pop()

Log in to reply
 

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