8-line simple Python DP solution


  • 0
    class Solution(object):
        def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            array = [0 for i in range(n + 1)]
            for i in range(1, n + 1):
                if i != n:
                    array[i] = i
                for j in range(1, i):
                    if array[j] * array[i - j] > array[i]:
                        array[i] = array[j] * array[i - j]
            return array[-1]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.