6-line Python solution


  • 0
    Z
        def minSteps(self, n):
            """
            :type n: int
            :rtype: int
            """
            def dp(n):
                if n==1:return 0
                for k in range(2,int(math.sqrt(n))+1):
                    if n % k ==0:return k+dp(n//k)
                return n
            return dp(n)
    

Log in to reply
 

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