Python easy standard backtracking

  • 0
    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:
                self.dfs(left // i, cur, ret)

Log in to reply

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