题目描述 难点主要是考虑整数拆成两个数之后不继续拆分的情况
class Solution:
def integerBreak(self, n: int) -> int:
dp = [0]*(n+1)
dp[2] = 1
for i in range(3,n+1):
for j in range(1,i-1):
dp[i] = max(dp[i],max(j*(i-j),j*dp[i-j]))
return dp[n]
运行结果: