O(n) Python


  • 0
    class Solution(object):
        def minSteps(self, n):
            if n == 1:
                return 0
            mf = self.maxF(n)
            print mf
            if mf == 1:
                return n
            return self.minSteps(mf) + (n / mf)
            
        def maxF(self, n):
            t = n - 1
            while t > 0:
                if n % t == 0:
                    return t
                t -= 1
    

Log in to reply
 

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