LeetCode.343. Integer Break
2016-05-03 20:18
357 查看
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.
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.
public class Solution { public int integerBreak(int n) { if(n==2) return 1; if(n==3) return 2; int a=n%3; int b=n/3; int num=0; switch (a) { case 0: num=(int) Math.pow(3,b);break; case 1: num=(int) (Math.pow(3,b-1)*4);break; case 2: num=(int) (Math.pow(3,b)*2);break; } return num; } }
相关文章推荐
- 为何一条短信可以发160个英文或70个汉字的原因
- 数据库基本概念
- GDOI2016总结
- LeetCode.342. Power of Four
- 网络地址为172.16.0.0,采用子网掩码255.255.224.0 .以下说法正确的是()
- CDMA订阅
- ehcache详解
- 常用算法整理:二叉树
- 十四、模版方法设计模式
- Android开发学习中的问题2016-5-03手动创建活动
- CoreData之增删改查
- HDU1010:Tempter of the Bone(DFS)
- [剑指offer]整数中1出现的次数(从1到n整数中1出现的次数)
- 欢迎使用CSDN-markdown编辑器
- 贝叶斯分类
- 使用Eclipse可以方便的统计工程或文件的代码行数,
- [NOI2004]郁闷的出纳员
- mongodb 常用操作
- 关于Ubuntu14.04 中文字体乱码问题
- 10.数值的整数次方