LeetCode-Integer Breaks
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.
Analysis:
Interesting problem. The solution is to create as many 3 as possible.
Solution:
public class Solution {
public int integerBreak(int n) {
if (n==2) return 1;
if (n==3) return 2;
if (n==4) return 4;
if (n==5) return 6;
return 3*Math.max(n-3,integerBreak(n-3));
}
}
LeetCode-Integer Breaks的更多相关文章
- [LeetCode] Integer Replacement 整数替换
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- [LeetCode] Integer Break 整数拆分
Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...
- [LeetCode] Integer to English Words 整数转为英文单词
Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...
- [LeetCode] Integer to Roman 整数转化成罗马数字
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- LeetCode "Integer Break"
A typical CS style DP based solution: class Solution(object): def __init__(self): self.hm = {} def i ...
- LeetCode Integer to English Words
原题链接在这里:https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to it ...
- Leetcode Integer Replacement
Given a positive integer n and you can do operations as follow: If n is even, replace n with n/2. If ...
- Leetcode Integer to Roman
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...
- [LeetCode]Integer Break(Dp或胡搞或推公式)
343. Integer Break Given a positive integer n, break it into the sum of at least two positive intege ...
- LeetCode: Integer to Roman 解题报告
Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...
随机推荐
- linux下启动、添加或删除服务命令
在Linux系统下,一个Services的启动.停止以及重启通常是通过/etc/init.d目录下的脚本来控制的.然而,在启动或改变运行级别时,是在/etc/rcX.d中来搜索脚本.其中X是运行级别的 ...
- Linux定时备份数据到百度云盘
导读:如今的百度云盘免费容量都是2T了,即使把电脑上所有的东东都放上去,也还有大把的剩余空间.对于站长来说,是完全可以充分利用这些硬盘空间的,现在我们就用百度云盘来备份Linux服务器上的数据. 一直 ...
- java大数模板
java 大数计算 这几天做了几道用大数的题,发现java来做大数运算十分方便.对acmer来说是十分实用的 1.valueOf(parament); 将参数转换为制定的类型 比如 int a=3 ...
- svn还原文件中去掉已经删除的文件
1.到svn目录下,选择文件并提交 2.在弹出的对话窗口中,选择文件并右击,找到"解决" 3.再次点击"还原"的时候,已经删除的文件就没有了.
- JavaScript 数组-Array的方法总结
JavaScript中的Array类型是经常用到的,Array类型也提供了很多方法能实现我们需求,下面我们来总结一下 一.创建Array的方法 1.使用Array构造函数 var colors=new ...
- [待解决]ColumnPrefixFilter 不能过滤出全部满足条件的,
Scan scan = new Scan(); ColumnPrefixFilter columnPrefixFilter = new hbase(main)::> scan 't4' ROW ...
- centos7.4 update git
1. 查看 yum 源仓库的 Git 信息: yum info git 输入如下内容: Available Packages Name : git Arch : x86_64 Version : 1. ...
- 在CentOS 7上利用systemctl添加自定义系统服务 /usr/lib/systemd/
在CentOS 7上利用systemctl添加自定义系统服务[日期:2014-07-21] 来源:blog.csdn.net/yuanguozhengjust 作者:yuanguozhengjust ...
- java为啥计算时间从1970年1月1日开始
http://www.myexception.cn/program/1494616.html ————————————————————————————————————————————————————— ...
- EasyUI combobox 加载JSON数据《一》
Action返回 JSON 格式如下: jsonResult = { total=7,rows=[ {TEXT=技术支持, ID=402894ca4419acf1014419b148a10000}, ...