343. Integer Break
2024-08-24 01:41:15
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.
思路:除了2和3以外,最终的结果是2和3的乘积,3多2少。
代码如下:
public class Solution {
public int integerBreak(int n) { if(n==2)
return 1;
if(n==3)
return 2; int result=1;
if(n%3==2)
{result=2;
n=n-2;
}
else if(n%3==1)
{
result=4;
n=n-4;
}
int count=n/3;
while(count>0)
{
result=result*3;
count--;
}
return result;
}
}
最新文章
- 安装LoadRunner提示缺少vc2005_sp1_with_atl..
- 【Python】-【类解析】--【脚本实例】
- Part 2: Oracle E-Business Suite on Cloud FAQ
- Linux下smokeping网络监控环境部署记录
- Spring的IOC注解学习
- 1396 - Most Distant Point from the Sea
- 该项目的建设maven片:4.协调和依赖,spring依赖注入demo
- 关于redis 缓存的问题
- 【Python3之面向对象的程序设计】
- 阻塞队列BlockingQueue
- Android中style和theme的区别
- STL常用整理
- Java数据结构和算法 - 哈希表
- java中的stream的泛型方法的使用示例
- jenkins深入学习
- Day7--------------IP地址配置
- Hbase启动hbase shell运行命令报Class path contains multiple SLF4J bindings.错误
- 微软BI 之SSRS 系列 - 报表邮件订阅中 SMTP 服务器匿名访问与 Windows验证, 以及如何成功订阅报表的实例
- supervisor control in centos 6/7 python2.6.2.7 3.4
- Qt5.3.2_CentOS6.4(x86)_代码文件编码