题目:

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. android持久化技术

    Android系统提供了3种持久化技术,所谓持久化技术是指将内存中的书籍保存在存储设备中. 1.文件存储 2.sharedPreference存储 3.数据库存储 除此之外,还可以将数据保存在SD卡中

  2. python画图

    正弦图像: #coding:utf-8import numpy as npimport matplotlib.pyplot as pltx=np.linspace(0,10,1000)y=np.sin ...

  3. 【算法】Hough变换

    终于看懂点了霍夫变换,以下内容来源为吉大的硕士论文,作者王阳阳 上图引用自 http://www.cnblogs.com/Ponys/p/3146753.html

  4. Oracle之常见问题诊断方法

    Oracle认证:常见问题诊断方法如下: 1.TNS-12154 Error 或ORA-12154 特征:SQL*NET没有找到连接串或别名 原因1:(1)没有找到TNSNAMES.ORA文件,该文件 ...

  5. JavaScript箭头函数 和 generator

    箭头函数: 用箭头定义函数........           var fun = x=>x*x alert(fun(2))            //单参数   var fun1 = ()=& ...

  6. 即时聊天IM之三 XMPP协议客户端库的和Android端框架概述

    合肥程序员群:49313181.    合肥实名程序员群:128131462 (不愿透露姓名和信息者勿加入) Q  Q:408365330     E-Mail:egojit@qq.com smack ...

  7. 仿W8屏保

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. ASP.NET MVC异步上传文件

    自己做的一个小dome.贴出来分享一下: 前端: <form id="formfile" method="post" enctype="mult ...

  9. ajax的探究与使用

    前端必须掌握ajax,这是几乎所有前端招聘都会要求的一项. 但其实ajax也就是一种异步请求的技术,没有什么很深的东西,不过接触ajax很长一段时间了,早该整理下ajax的学习和使用: PART1: ...

  10. 在CentOS 6.7中安装NVIDIA GT730显卡驱动的手记

    主机: Dell OptiPlex 390 MT (i5) 系列: 主机原配独显,型号未知,运转三年半,常有异响,关机之后过一阵再开机,可以解决.最近,风扇的声音实在不正常,重启也无解,判定它挂了.风 ...