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

343. Integer Break的更多相关文章

  1. LN : leetcode 343 Integer Break

    lc 343 Integer Break 343 Integer Break Given a positive integer n, break it into the sum of at least ...

  2. #Week 11 - 343.Integer Break

    Week 11 - 343.Integer Break Given a positive integer n, break it into the sum of at least two positi ...

  3. 【LeetCode】343. Integer Break 解题报告(Python & C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 数学解法 动态规划 日期 题目地址:https:// ...

  4. [LeetCode] 343. Integer Break 整数拆分

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  5. (dp)343. Integer Break

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  6. Leetcode 343. Integer Break

    Given a positive integer n, break it into the sum of at least two positive integers and maximize the ...

  7. leetcode@ [343] Integer Break (Math & Dynamic Programming)

    https://leetcode.com/problems/integer-break/ Given a positive integer n, break it into the sum of at ...

  8. 343. Integer Break -- Avota

    问题描述: Given a positive integer n, break it into the sum of at least two positive integers and maximi ...

  9. LeetCode题解 343.Integer Break

    题目:Given a positive integer n, break it into the sum of at least two positive integers and maximize ...

随机推荐

  1. 提升WordPress站点速度的八个建议

    WordPress是一个很棒的开源程序,几乎我认识的站长朋友当中,粗略估算有80%使用Wordpress.但很棒不等于完美,就在我所认识的这些朋友中,几乎所有人都会抱怨Wordpress太臃肿,运行效 ...

  2. CNAPS Code 查询(招商银行)

    招商银行的妹子实在太傻了,根本不知道什么是CNAPS Code.联行号,完全答非所问. 最后还是自己搞定了,如图: 最后再看看招行人员的英语水平,真是不知道什么是东西:

  3. C#获取本机mac地址

    添加System.Management的引用, using System.Management; string mac = ""; ManagementClass mc = new ...

  4. 【codevs2370】小机房的树 LCA 倍增

    2370 小机房的树  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 钻石 Diamond 题目描述 Description 小机房有棵焕狗种的树,树上有N个节点,节点标号为0 ...

  5. 2、IValueConverter应用

    1.C#代码如下: public class logotoimgConverter:IValueConverter { //将logo转换为URI public object Convert(obje ...

  6. 学好C++必须要注意的十八个问题

    转自  http://blog.chinaunix.net/uid-7396260-id-2056691.html 一.#include "filename.h"和#i nclud ...

  7. 我认为测试应该掌握的SQL语句

    最近在学习Oracle,对测试人员而言必须掌握两种语言:第一种是DML,数据操纵语言 (Data Manipulation Language) 是SQL语言中,负责对数据库对象运行数据访问工作的指令集 ...

  8. Oracle GoldenGate 12c (12.1.2.0.1) for IBM DB2 iSeries

    OGG 12.1.2.0.1 for iSeries 在2014.2.15发布,主要新增如下功能: 本地交付(Native Delivery Replicat):新功能允许用户在IBM i服务器上安装 ...

  9. zookeeper3.4.6的安装

    最近为了解决HDFS的单点故障的问题,采用了HA的方式是实现,并通过zookeeper来实现自动切换,既然需自动切换的话,那么必须要安装zookeeper,我选用的版本是3.4.6.下面详细介绍一下其 ...

  10. 《Java7中 下划线的新特性》

    //Java7引入了一个新功能:程序员可以在数值中使用下画线,不管是 //整形数值,还是浮点型数值,都可以自由地使用下划线.通过下划线 //分隔,可以更直观的分辨数值中到底有多少位. public c ...