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

全部评论

相关推荐

05-27 14:57
西北大学 golang
强大的社畜在走神:27届真不用急,可以搞点项目、竞赛再沉淀沉淀,我大二的时候还在天天打游戏呢
投递华为等公司10个岗位
点赞 评论 收藏
分享
陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-11 11:22
怎么这么多逆天求职者,救救我救救我救救我😭
flmz_Kk:哈哈哈哈哈哈,这么多求职者,肯定有那一两个逆天的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务