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. Docker构建nginx的nginx-rtmp-module视频服务器镜像

    文章地址:https://www.cnblogs.com/linyilong3/p/5862595.html GitHub nginx-rtmp-module 及配置 Dockerfile构建配置: ...

  2. Android简单介绍

    1)Android定义: 2)版本号变迁 3)开发类型 4)Android五大组件 5)Android五大布局

  3. XML - 十分钟了解XML结构以及DOM和SAX解析方式

    引言 NOKIA 有句著名的广告语:"科技以人为本".不论什么技术都是为了满足人的生产生活须要而产生的.详细到小小的一个手机.里面蕴含的技术也是浩如烟海.是几千年来人类科技的结晶, ...

  4. WebKit(Blink分支)各组件的创建与逻辑关系

    从render_view_impl.cc開始说起. 1.     方法RenderViewImpl::Initialize中有: WebLocalFrame* web_frame = WebLocal ...

  5. mac ssh 命令

    https://www.cnblogs.com/littleBit/p/5362806.html 1.终端命令 1.打开Mac的命令终端,检查是不是用root登陆,如果不是的话,就输入命令:sudo ...

  6. day5:协成函数与import、for...import...的使用

    一.协程函数 1.把函数的执行结果封装好__iter__和__next__,即得到一个迭代器2.与return功能类似,都可以返回值,但不同的是,return只能返回一次值,而yield可以返回多次值 ...

  7. 使用7za压缩zip包的命令,当中屏蔽部分文件夹内容

    7za.exe a -r  "D:\paages\prduct\produtConfig.zip" "E:/tm\packaes\poduct" -xr!doc ...

  8. 项目红色感叹号eclipse因Web App Libraries中的jar包missing导致项目红色感叹号

    症状: 如题 分析: 修改.更换或者删除了WEB-INF/lib中的jar包 解决方案: 右击项目>build path>Libraries 直接remove Web App Librar ...

  9. 写一个php小脚本辅助渗透测试

    因为一个注入要爬行一些数据,然后写的一个小脚本,能写脚本来辅助渗透,也算是里程碑.哈哈哈 <?php $num = 1; while ($num <= 39) { $web_url = & ...

  10. [Python]计算闰年时候出现的and和or优先级的问题以及短路逻辑

    好吧题目非常easy.可是有些细节还是挺有意思的. 题目是:计算今年是否是闰年,推断闰年条件,满足年份模400为0,或者模4为0可是模100不为0 答案是这种: import time #计算今年是否 ...