343. Integer Break
2017-06-22 22:39
316 查看
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.
For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).
Note: You may assume that n is not less than 2 and not larger than 58.
For example, given n = 2, return 1 (2 = 1 + 1); given n = 10, return 36 (10 = 3 + 3 + 4).
Note: You may assume that n is not less than 2 and not larger than 58.
class Solution(object): def integerBreak(self, n): """ :type n: int :rtype: int """ dp = [0, 0, 1] for i in xrange(3, n+1): max_product = i - 1 for j in xrange(2, i // 2+1): max_product = max(max_product, max(j, dp[j]) * max(i - j, dp[i - j])) dp.append(max_product) return dp
相关文章推荐
- leetcode343 Integer Break
- 343. Integer Break #Medium
- 动态规划2-Leetcode343-integerBreak
- 343. Integer Break
- 343. Integer Break
- leetcode@ [343] Integer Break (Math & Dynamic Programming)
- 343. Integer Break
- leetcode343 Integer Break java
- leetcode:数学:Integer Break(343)
- [343]Integer Break
- 343. Integer Break
- 343. Integer Break
- leetcode343-Integer Break(整数拆分求最大乘积)
- 343. Integer Break
- 343. Integer Break
- 343. Integer Break
- 343. Integer Break
- 343. Integer Break
- LeetCode 343 Integer Break
- 343. Integer Break