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;
}
}

最新文章

  1. 安装LoadRunner提示缺少vc2005_sp1_with_atl..
  2. 【Python】-【类解析】--【脚本实例】
  3. Part 2: Oracle E-Business Suite on Cloud FAQ
  4. Linux下smokeping网络监控环境部署记录
  5. Spring的IOC注解学习
  6. 1396 - Most Distant Point from the Sea
  7. 该项目的建设maven片:4.协调和依赖,spring依赖注入demo
  8. 关于redis 缓存的问题
  9. 【Python3之面向对象的程序设计】
  10. 阻塞队列BlockingQueue
  11. Android中style和theme的区别
  12. STL常用整理
  13. Java数据结构和算法 - 哈希表
  14. java中的stream的泛型方法的使用示例
  15. jenkins深入学习
  16. Day7--------------IP地址配置
  17. Hbase启动hbase shell运行命令报Class path contains multiple SLF4J bindings.错误
  18. 微软BI 之SSRS 系列 - 报表邮件订阅中 SMTP 服务器匿名访问与 Windows验证, 以及如何成功订阅报表的实例
  19. supervisor control in centos 6/7 python2.6.2.7 3.4
  20. Qt5.3.2_CentOS6.4(x86)_代码文件编码

热门文章

  1. HDU 4050 wolf5x 概率dp 难度:1
  2. 二模 (13)day1
  3. redis学习(一)
  4. Android VersionedGestureDetector手势事件
  5. java基础之 泛型
  6. 微软.NET Framework 4.5.2 RTM正式版
  7. 《使用this作为返回值的相关问题》
  8. JS 基础事件的用法
  9. 使用sslsplit嗅探tls/ssl连接
  10. C++实现python标准库中的Counter