A typical CS style DP based solution:

class Solution(object):
def __init__(self):
self.hm = {} def integerBreak(self, n):
if n in self.hm:
return self.hm[n]
ret = 0
for i in range(1, n//2 + 1):
v1 = self.integerBreak(i)
v2 = self.integerBreak(n - i)
ret = max(ret, v1 * v2, v1 * (n - i), i * v2, i * (n - i))
self.hm[n] = ret
return ret

But there's a Math based solution:

https://leetcode.com/discuss/98249/easy-to-understand-c-with-explanation
In which: "For any integer p strictly greater than 4, it has the property such that 3 * (p - 3) > p, which means breaking it into two integers 3 and p - 3 makes the product larger while keeping the sum unchanged"

LeetCode "Integer Break"的更多相关文章

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

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

  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 Break

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

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

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

  5. LeetCode 343. 整数拆分(Integer Break) 25

    343. 整数拆分 343. Integer Break 题目描述 给定一个正整数 n,将其拆分为至少两个正整数的和,并使这些整数的乘积最大化. 返回你可以获得的最大乘积. 每日一算法2019/5/2 ...

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

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

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

  9. leetcode 343. Integer Break(dp或数学推导)

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

随机推荐

  1. HTML中的target(_self,_blank)用法总结

    HTML中的target(_self,_blank)用法总结 最近一个项目,多次遇到target='_self', target='_blank'的用法, 再次总结一下: 1.<a>标签 ...

  2. TestLink

    TestLink的主要功能包括: 测试需求管理 测试用例管理 测试用例对测试需求的覆盖管理 测试计划的制定 测试用例的执行 大量测试数据的度量和统计功能 TestLink的主要特色包括: 支持多产品或 ...

  3. [maven] maven变量

    Maven内置变量说明: $${project.basedir}或{basedir} 项目根目录,即包含pom.xml文件的目录 ${project.version}或${version}表示项目版本 ...

  4. 51nod 1027大数乘法

    题目链接:51nod 1027大数乘法 直接模板了. #include<cstdio> #include<cstring> using namespace std; ; ; ; ...

  5. Java:多线程<四> Lock、停止线程、守护线程、join、优先级&yield

    Java1.5以后,Condition将Object监视器方法(wait, notify, notifyAll)分解成截然不同的对象,以便通过这些对象与任意Lock实现组合使用为每个对像提供多个等待s ...

  6. 手机抓包-fiddler

    如果app走的是http协议,不用root,只需要通过fiddler做代理,就可以抓到所有请求. 1. fiddler+手机wifi设置 安装fiddler,勾中 Fiddler Options -& ...

  7. android 分享或者调用系统或者其他app时 应注意! startActivityForResult() 使用

    //判断是否有相应的Activity来接受intentPackageManager packageManager = getPackageManager();List<ResolveInfo&g ...

  8. 从0到1---“保多多”APP的开发(一)

    2015年8月份,我正式接手了公司保多多APP的开发(和另一个同事一起). 我之前并没有过从0开始创建一款APP,这次能有这样的机会,实在让我感到兴奋.因为我相信,作为这款APP的主要开发人员,在这一 ...

  9. Python学习笔记-字符串

    Python之使用字符串 1.所有的标准序列操作(索引,分片,乘法,判断成员资格,求长度,取最小值,最大值)对字符串同样适用.但是字符串都是不可变的. 2.字符串格式化使用字符串格式化操作符即%. f ...

  10. libdispatch for Linux

    这个Dispatch是苹果的一个高效的处理库,它在ubuntu上的安装如下: Build/Runtime Requirements 如下: libBlocksRuntime libpthread_wo ...