题目:

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).

实现:

 class Solution {
public:
int integerBreak(int n) {
if (n == )
return ;
if (n == )
return ;
int res = ;
while (n>)
{
res *= ;
n -= ;
}
if (n == )
return res;
if (n == )
return (res / ) * ;
if (n == )
return res*;
return -;
}
};

分析:要得到最大,就需要尽可能多地分解出3,但是不能分解出1.那么分解出了1,就需要把它变成4.

Integer Break(Difficulty: Easy)的更多相关文章

  1. Number of 1 Bits(Difficulty: Easy)

    题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also ...

  2. Power of Four(Difficulty: Easy)

    题目: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example ...

  3. 【LeetCode-面试算法经典-Java实现】【139-Word Break(单词拆分)】

    [139-Word Break(单词拆分)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a string s and a dictionary of w ...

  4. 【POJ 1716】Integer Intervals(差分约束系统)

    id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS   Memory L ...

  5. leetcode-8-String to Integer (atoi) (已总结)

    8. String to Integer (atoi) Total Accepted: 93917 Total Submissions: 699588 Difficulty: Easy Impleme ...

  6. synchronized 加锁Integer对象(数据重复)详解

    场景描述:多线程输出1到100,对静态Integer对象加锁,synchronized代码块中操作Integer对象,发生线程安全问题(数据重复) 代码: public class MyRunnabl ...

  7. 抓取网站数据不再是难事了,Fizzler(So Easy)全能搞定

    首先从标题说起,为啥说抓取网站数据不再难(其实抓取网站数据有一定难度),SO EASY!!!使用Fizzler全搞定,我相信大多数人或公司应该都有抓取别人网站数据的经历,比如说我们博客园每次发表完文章 ...

  8. hdu 3681 Prison Break (TSP问题)

    Prison Break Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  9. leetcode 解题 String to Integer (atoi)(C&python)

    //此题是easy题,比较简单,主要困难在考虑全输入的各种情况://1.开始的时候有空格等空白字符//2.开头有加减号//3.溢出(第一次写就是没有考虑到这个情况) //C代码int myAtoi(c ...

随机推荐

  1. 20161117__Z

    1.cclplus: error: unrecognized command line option "-std=gnu++11" http://www.gowhich.com/b ...

  2. Android之mtk上传log

    Android之mtk上传log 1,打开浏览器 2.输入地址http://eservice.mediatek.com/eservice-portal/login 3.输入用户名,密码 4.提eser ...

  3. IO流中SequenceInputStream类

    SequenceInputStream类: 不断的读取InputStream流对象,对于使用Enumeration对象的情况,该类将持续读取所有InputStream对象中的内容,直到到达最后一个In ...

  4. ajax和sap以及网络安全

    1.sap(single page  applaction)一个页面通过众多ajax请求完成的一个app 优点是:减少页面跳转,UI公用部分的重复加载 缺点: 1.ajax过多的请求,对服务器性能有所 ...

  5. Sql Server如何新建计划任务

    打开Sql Server数据库,在管理中找到维护计划功能,右击维护计划选择维护计划向导.如图所示: 打开维护计划向导后,在第一个步骤下输入计划名称. 输入完计划名称后,点击右下角的更改按钮,这里是配置 ...

  6. Discuz! X论坛上传附件到100%自动取消上传的原因及解决方案

    最近接到一些站长的反馈,说论坛上传附件,到100%的时候自己取消上传了.经查是附件索引表pre_forum_attachment表的aid字段自增值出现了问题,导致程序逻辑返回的aid值实际为一个My ...

  7. python3内置函数

    abs()Return the absolute value of a number. The argument may be an integer or a floating point numbe ...

  8. scalac 学习

    val logEnable = false def log(msg: => String) = if (logEnable) println(msg) val MSG = "progr ...

  9. daydayup2 codeforces143C

    题意:给你n= (A - 1) × (B - 2) × (C - 2),求A*B*C的最大值和最小值 思路:要用好的姿势暴力 #include "stdio.h" #include ...

  10. .NET程序的简单编译原理

    1.不管是什么程序,最终的执行官是CPU,而CPU只认识1和0的机器码. 2.我们现在写的一般是高级语言写的程序.CPU是不认识我们用高级语言写的源代码的,那应该怎么办才能让CPU执行我们写好的程序尼 ...