Python dp solution(58ms)


  • 0
    J
    class Solution(object):
        def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            result = [1, 1]
            for i in range(2, n):
                current_n = i + 1
                temp = 0
                for j in range(0, i):
                    take_n = j + 1
                    temp = max(temp, max(take_n, result[take_n - 1]) * max(current_n - take_n, result[current_n - take_n - 1]))
    
                result.append(temp)
            return result[n - 1]

Log in to reply
 

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