Python, Simple


  • 0
    3
    class Solution:
        def minSteps(self, n):
            """
            :type n: int
            :rtype: int
            """
            dp = [i for i in range(n+1)]
            dp[1] = 0
            if n<=1: return dp[n]
            dp[2] = 2
            for i in range(3,n+1):
                for j in range(2,i//2+1):
                    if i%j==0:
                        dp[i] = min(dp[i],dp[j]+i//j)
            return(dp[n])
    

Log in to reply
 

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