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的更多相关文章

  1. [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 ...

  2. [LeetCode] Integer Break 整数拆分

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

  3. [LeetCode] Integer to English Words 整数转为英文单词

    Convert a non-negative integer to its english words representation. Given input is guaranteed to be ...

  4. [LeetCode] Integer to Roman 整数转化成罗马数字

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  5. LeetCode "Integer Break"

    A typical CS style DP based solution: class Solution(object): def __init__(self): self.hm = {} def i ...

  6. LeetCode Integer to English Words

    原题链接在这里:https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to it ...

  7. 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 ...

  8. Leetcode Integer to Roman

    Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 t ...

  9. [LeetCode]Integer Break(Dp或胡搞或推公式)

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

  10. LeetCode: Integer to Roman 解题报告

    Integer to Roman Given an integer, convert it to a roman numeral. Input is guaranteed to be within t ...

随机推荐

  1. 巧用FTP命令进行文件传输

    巧用FTP进行文件传输   Internet作为现代信息高速公路已深入我们的生活,其中它所提供的电子邮件Web网站信息服务已被越来越多的人所熟知和使用.FTP作为Internet的功能之一,虽然没有像 ...

  2. Bootstrap学习笔记 Well

    Well是一种会引起内容凹陷或插图效果的容器div.为了创建Well,只需要简单地把内容放在带有class well的div中即可.下面的实例演示了默认的Well: html: <div> ...

  3. mongodb - save()和insert()的区别

    遇到_id相同的情况下:insert操作会报错:save完成保存操作 > db.person.find() > db.person.insert({"_id":1,ag ...

  4. 多校第九场Arithmetic Sequence题解

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5400 题意:给定等差数列的差值d1,d2.问长度为n的数列中有多少个满足条件的子序列,条件为子序列中 ...

  5. linux下的几个cd命令

    linux cd命令 cd data 进入到 data 目录 cd .. 返回上级文件夹 cd ~ 返回用户主文件夹 cd / 返回根文件夹

  6. Atitit.ui控件---下拉菜单选择控件的实现select html

    Atitit.ui控件---下拉菜单选择控件的实现select   html 1. 调用& model的实现 1 2. -----select.jsp------ 1 1. 调用& m ...

  7. Redis-ha(sentinel)

    redis的sendtinel 是用来管理多个redis服务器的 作用 • 监控:监控主从服务器是否运作正常(通过给服务器发送心跳包的方式)    • 提醒:当某个Redis服务器出现异常时,可以通过 ...

  8. cocos2dx触摸

    两种方法其实都一样,CCLayer也是继承CCTouchDelegate. 1.继承CCTouchDelegate 添加触摸代理 CCTouchDispatcher* pDispatcher = CC ...

  9. apache ab测试

    网站并发测试,网站服务使用的是apache2.4 因此使用ab来测试网站性能. windows使用cms 打开apache/bin 运行ab.exe (......../apache/bin/ab), ...

  10. (转)RISC-V结构逻辑图

    转载地址:http://blog.csdn.net/zzwu/article/details/54810162 说明: 执行6级流水作业: 1. fetch(取指) 2. decode(译码) 3. ...