python code beats 100%


  • 2
    Z

    This is essentially factorization of a integer, you find all its factors, and add them together
    The code used a simple divide and conquer model, iterative might do better

    def minSteps(self, n):
            if n==1:
                return 0
            f = 1
            for i in range(int(n**0.5),0,-1):
                if n%i ==0:
                    f =i
                    break
            if f == 1:
                return n
            return int(self.minSteps(f) + self.minSteps(n/f))
    

  • 0
    C

    @zhangsikai123

    Good job. Similar to what I did during the contest.


Log in to reply
 

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