Integer Break
Problem: Integer Break
For 7, it's 322. For numbers following 7, if the previous product is even, replace a 2 with 3. If not, replace a 3 with 4 (2*2).
Code in Python:
class Solution(object):
def integerBreak(self, n):
"""
:type n: int
:rtype: int
"""
res = [0, 0, 1, 2, 4, 6, 9]
for i in xrange(7, n+1):
if res[-1] % 2:
res.append(res[-1]/3*4)
else:
res.append(res[-1]/2*3)
return res[n]