We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
343. 整数拆分
给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。
示例1:
输入: 2 输出: 1 解释: 2 = 1 + 1, 1 × 1 = 1。
示例2:
输入: 10 输出: 36 解释: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36。
提示:你可以假设 n 不小于 2 且不大于 58。
The text was updated successfully, but these errors were encountered:
dp 解法
dp[i] = max
i = j + (i - j)
j * (i - j)
j * dp[i - j]
1
/** * @param {number} n * @return {number} */ var integerBreak = function(n) { const dp = Array(n + 1).fill(1); for (let i = 3; i <= n; i++) { for (let j = 2; j < i; j++) { dp[i] = Math.max( dp[i], j * (i - j), j * dp[i - j] ); } } return dp[n]; };
Sorry, something went wrong.
No branches or pull requests
题目
给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化。 返回你可以获得的最大乘积。
示例1:
示例2:
提示:你可以假设 n 不小于 2 且不大于 58。
The text was updated successfully, but these errors were encountered: