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. 如何禁用IE10的明文显示密码和快速清除功能

    IE10针对 <input>及<input type="password"> 分别提供了快速清除钮(X图标)以及密码文字显示钮(小眼睛图标)的功能: 快速清 ...

  2. ASCII十进制字符集

    <script> for(var i=33;i<=6000;i++){ document.write("&nbsp"+i+"&nbsp ...

  3. px和em

    相同点: 都是长度单位 不同点: px是绝对单位,不支持IE的缩放,em是相对单位. px的值是固定的,指定是多少就是多少:em得值不是固定的,并且em会继承父级元素的字体大小 ps: 浏览器的默认字 ...

  4. c#调用c++动态链接库的问题

    1. Server Error in '/' Application. Object reference not set to an instance of an object. 这个问题是接口中的方 ...

  5. mysql分组查询取分组后各分组中的最新一条记录

    SELECT * FROM ( SELECT * FROM `CFG_LOGIN_LOG` ORDER BY LOGTIME DESC ) test GROUP BY login_name DESC

  6. 英文缩写&名词

    DAO:Data Access Object 数据访问对象 Abstract Oriented Programing 面向借口编程 IOC: Inversion of Control 控制反转 DI: ...

  7. Linux (Ubuntu) 下配置VPN服务器

    昨天网上找了下VPN的相关信息,居然各种撞墙,特别郁闷,自己不容易找到的东西,记录下VPN的配置信息 ubuntu 13.1下配置VPN  ,采用PPTP实现, 第一步.安装pptpd,没有安装包记得 ...

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

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

  9. Binary Tree Inorder Traversal -- LeetCode 94

    Given a binary tree, return the inorder traversal of its nodes' values. For example:Given binary tre ...

  10. ”isEqual“ ”isEqalToString“ 和“==”三者区别

    isEqual :首先判断的时对象类型是否 一样,然后再判断具体内容是否一致:如果类型不一样,return no: isEqualToString: 直接判断字符串内容,便捷更快速,但是前提确保比较的 ...