Integer Break(Difficulty: Easy)
题目:
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)的更多相关文章
- Number of 1 Bits(Difficulty: Easy)
题目: Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also ...
- Power of Four(Difficulty: Easy)
题目: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example ...
- 【LeetCode-面试算法经典-Java实现】【139-Word Break(单词拆分)】
[139-Word Break(单词拆分)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a string s and a dictionary of w ...
- 【POJ 1716】Integer Intervals(差分约束系统)
id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS Memory L ...
- leetcode-8-String to Integer (atoi) (已总结)
8. String to Integer (atoi) Total Accepted: 93917 Total Submissions: 699588 Difficulty: Easy Impleme ...
- synchronized 加锁Integer对象(数据重复)详解
场景描述:多线程输出1到100,对静态Integer对象加锁,synchronized代码块中操作Integer对象,发生线程安全问题(数据重复) 代码: public class MyRunnabl ...
- 抓取网站数据不再是难事了,Fizzler(So Easy)全能搞定
首先从标题说起,为啥说抓取网站数据不再难(其实抓取网站数据有一定难度),SO EASY!!!使用Fizzler全搞定,我相信大多数人或公司应该都有抓取别人网站数据的经历,比如说我们博客园每次发表完文章 ...
- hdu 3681 Prison Break (TSP问题)
Prison Break Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- leetcode 解题 String to Integer (atoi)(C&python)
//此题是easy题,比较简单,主要困难在考虑全输入的各种情况://1.开始的时候有空格等空白字符//2.开头有加减号//3.溢出(第一次写就是没有考虑到这个情况) //C代码int myAtoi(c ...
随机推荐
- C#基础2
namespace 基础 //定义一个命名空间,为基础 { class Program //定义一个名称为Program的类 { static void Main(string[] args) //这 ...
- python中的动态变量
def make_name(): names = locals() for i in range(1, 10): names['t%s' % i] = i print names['t%s' % i]
- C++ void*的使用
void*类型可以存储任何类型的指针,使用的时候强制转化成对应类型的指针便可. #include <iostream> #include <vector> using name ...
- 关于app隐私设置跳转
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]] ...
- 利用Excel表格中的宏,轻松提取首字母
1.启动Excel 2003(其它版本请仿照操作),打开相应的工作表: 2 2.执行“工具→宏→Visual Basic编辑器”命令(或者直接按“Alt+F11”组合键),进入Visual Basic ...
- ionic,angularJs实现搜索框过滤关键字
利用AngularJS自带的过滤器,我们可以很方便的实现搜索框过滤的效果,但是怎么实现类似百度搜索过滤列表中关键字变色的效果呢? 页面上代码: <input type="text&qu ...
- java selenium (六) XPath 定位
xpath 的定位方法, 非常强大. 使用这种方法几乎可以定位到页面上的任意元素. 阅读目录 什么是xpath xpath 是XML Path的简称, 由于HTML文档本身就是一个标准的XML页面, ...
- 实战Nginx与PHP(FastCGI)的安装、配置与优化
一.什么是 FastCGIFastCGI是一个可伸缩地.高速地在HTTP server和动态脚本语言间通信的接口.多数流行的HTTP server都支持FastCGI,包括Apache.Nginx和l ...
- RSA加密,应用授权及MSSQL备份与还原
01.QBRSA加解密处理 --> a.利用 RSA密钥生成器生成密钥(e,n,d) [e,n]为私钥, [d,n]为公钥 b.正向加密: 用私钥加密,用公钥解密 c.反向加密: 用公钥加密 ...
- 汽车驱动之家 http://bmw360.cn
汽车驱动之家 http://bmw360.cn