题目:

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. django数据库的增删改查

    正常启动服务安装数据库cmd命令:python manage.py makemigrations 创建用户 在pxm里面会有一个py文件..这就是生成了表结构cmd命令:python manage.p ...

  2. C++输入cout与输出cin

    输入和输出并不是C++语言中的正式组成成分.C和C++本身都没有为输入和输出提供专门的语句结构.输入输出不是由C++本身定义的,而是在编译系统提供的I/O库中定义的.C++的输出和输入是用" ...

  3. i.Windows下APR安装过程

    1.下载安装native Windows下的APR安装和配置比较简单,可以直接下载Tomcat-native的二进制的版本包: 下载之后的目录结构为: tcnative-1.dll这个库已经包含了AP ...

  4. Fibers in JVM

    转载: Fibers in JVM

  5. JS 劫持来源网站并做指定跳转

    有时候给网站做流量,免不了要做一些网站劫持的JS跳转,这里贴上一段劫持来源网站的JS跳转方法,很简单 <script> // 获取来源网站 var slyar = document.ref ...

  6. input框只能输入整数和浮点数非数字就不输入

    <input type="text" onInput="clearNoNum(this)" > //需引入jquery <script> ...

  7. NoSQL生态系统——事务机制,行锁,LSM,缓存多次写操作,RWN

    13.2.4 事务机制 NoSQL系统通常注重性能和扩展性,而非事务机制. 传统的SQL数据库的事务通常都是支持ACID的强事务机制.要保证数据的一致性,通常多个事务是不可能交叉执行的,这样就导致了可 ...

  8. TypeError: window.open is not a function

    想必大家现在都已经到家了,而苦逼的我还要坐在办公室混拿微薄的工资,技不如人,平常不努力给自己充电,年终一毛钱都没多给.不说这扫兴的话题了,在这给同样在苦逼坚守岗位的同志们节日的问候,新的一年,好运连连 ...

  9. 艺萌TCP文件传输及自动更新系统介绍(TCP文件传输)(四)

    艺萌TCP文件上传下载及自动更新系统介绍(TCP文件传输) 该系统基于开源的networkComms通讯框架,此通讯框架以前是收费的,目前已经免费并开源,作者是英国的,开发时间5年多,框架很稳定. 项 ...

  10. 为iOS的mobileconfig文件进行签名

    本文主要讲,使用苹果开发者证书进行签名达到目的,本文两种方法,一种是刀耕火种的一步步操作,一种使用脚本签名 一.导出苹果证书进行签名 1.从钥匙串(keychain)中导出证书 实用工具->钥匙 ...