leetcode:数学:Integer Break(343)

原创 2016年08月31日 14:17:39

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.

Show Hint


http://www.cnblogs.com/grandyang/p/5411919.html

class Solution {
public:
    int integerBreak(int n) {
        if (n == 2 || n == 3) return n - 1;
        int res = 1;
        while (n > 4) {
            res *= 3;
            n -= 3;
        }
        return res * n;
    }
};
版权声明:本文为博主原创文章,未经博主允许不得转载。

LeetCode解题报告 343. Integer Break [medium]

题目描述 Given a positive integer n, break it into the sum of at least two positive integers and maximi...

LeetCode 343. Integer Break 动态规划,状态转移方程

343. Integer Break Given a positive integer n, break it into the sum of at least two positive inte...

[LeetCode]problem 343. Integer Break

TAG分解n得到长度至少为2、和为n的数字序列,使其乘积最大的方法——一直从中分出3。数学 题目链接方法懵逼。按照提示找规律,然而也没有找到。果然智障。看了DISCUZZWhy factor 2 or...

LeetCode笔记:343. Integer Break

拆分正整数成多个数相加,得出最大乘积

Leetcode 343. Integer Break

原题链接: 343. Integer Break 343. Integer Break    My Submissions Question Editorial Solution T...

<LeetCode OJ> 343. Integer Break

Total Accepted: 2481 Total Submissions: 5881 Difficulty: Medium Given a positive integer n, bre...

LeetCode #343 - Integer Break - Medium

ProblemGiven a positive integer n, break it into the sum of at least two positive integers and maxim...
  • Arcome
  • Arcome
  • 2016年11月02日 08:49
  • 154

leetcode 343. Integer Break

今天开始抽空把我在leetcode上 刷到的一些题及思路搬到这里来。我是半吊子水平,所以此举绝不是炫耀,主要目的是对自己做过的东西做个记录,当然如果能对任何人有所启发,那就太荣幸了。OK少说废话了,说...

343. Integer Break 等

343. Integer Break 原题: Given a positive integer n, break it into the sum of at least two positi...
  • Mr_Zing
  • Mr_Zing
  • 2016年10月23日 11:26
  • 265

[LC343] Integer Break

343. Integer Break Given a positive integer n, break it into the sum of at least two positive inte...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:leetcode:数学:Integer Break(343)
举报原因:
原因补充:

(最多只允许输入30个字)