Easy Python DP Solution


  • 0
    S
    def integerBreak(self, n):
    
        dp = [0]*(n+1)
        dp[1] = 1
        dp[2] = 1
        for i in range(3,n+1) : 
            for j in range(1,i):
                dp[i] = max(dp[i-j] * dp[j] , dp[i])
                dp[i] = max(dp[i-j] * j , dp[i])
                dp[i] = max( (i - j) * dp[j] , dp[i])
                dp[i] = max((i - j) * j , dp[i])
        return dp[n]

Log in to reply
 

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