Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.
Input: 2 Output: 1 Explanation: 2 = 1 + 1, 1 × 1 = 1.
class Solution: def integerBreak(self, n: int) -> int: if n == 2: return 1 elif n == 3: return 2 else: sum1 = 1 while n > 4: sum1 *= 3 n -= 3 sum1 *=n return sum1
这道题方法很多,最简单的就是找规律,当然也可以采用dp来做。