<span>leetcode-343 Integer Break</span>

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来做。

全部评论

相关推荐

给🐭🐭个面试机会吧:我boss直聘天天有家教跟我打招呼😓
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务