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. Python之基础数学知识

    一.线性代数 1.求转置 import numpy m = numpy.mat([[1, 2], [3, 4]]) print("Matrix.Transpose:") print ...

  2. 使用cros实现跨域请求

    直接上代码 后端 this.Response.Headers.Add("Access-Control-Allow-Origin","*"); 响应流里添加一个h ...

  3. WPF自定义控件之水印文本(密码)框

    首先来讲讲创建这个控件的初衷,一个让我很郁闷的问题. 公司的客户端项目采用WPF+MVVM技术实现,在近期地推客户端的过程中遇到了一个很奇葩的问题:在登录界面点击密码框就会直接闪退,没有任何提示 密码 ...

  4. 聚合类新闻client的改进

         zaker和鲜果是最早的聚合类新闻产品.前几年发展非常快.迅速占据了市场,但近两年发展变得缓慢.而今日头条自公布以来才两年.用户量就迅速超过了zaker和鲜果.使用起来非常easy,左右滑动 ...

  5. NGUI ScrollView中MoveRelative,Scroll的区别

    Scroll会计算边界,和直接拖拽的效果类似 MoveRelative不计算边界,超出边界了也不会管,也不会应用缓动效果

  6. WatiN自动化测试

    简介 WatiN - Watir的.NET版: http://watin.sourceforge.net/ Welcome at the WatiN (pronounced as What-in) w ...

  7. PHP命名空间规则解析及高级功能

    日前发布的PHP .3中,最重要的一个新特性就是命名空间的加入.本文介绍了PHP命名空间的一些术语,其解析规则,以及一些高级功能的应用,希望能够帮助读者在项目中真正使用命名空间. 在这里中我们介绍了P ...

  8. 文件IO之——阻塞和非阻塞及perror函数

    读常规文件是不会阻塞的,不管读多少字节,read一定会在有限的时间内返回.从终端设备或网络读则不一定,如果从终端输入的数据没有换行符,调用read读终端设备就会阻塞,如果网络上没有接收到数据包,调用r ...

  9. sublimtext3 自定义编译环境

    sublime text是一个非常神奇到编辑器,对于我这种小白来说,感觉比vim好用,但是如果用sublime自带到编译环境到话,是没法向程序汇总输入数据的,所以要自己新建编译命令 { "c ...

  10. poll?transport=longpoll&connection...连接的作用

    在浏览器中打开使用VS2013开发的项目时,按F12使用浏览器调试,会发现一堆无关的请求,结构大致是:poll?transport=longpoll&connection.....一直不停的请 ...