Two python solutions


  • 0
    S
    class Solution(object):
        def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            dp = [0, 0, 1]
            for i in range(3, n+1):
                dp.append(0)
                for j in range(i):
                    dp[i] = max(dp[i], max(dp[i-j], i-j)*max(dp[j], j))     
            return dp[n]
    
    class Solution(object):
        def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            if n == 2:
                return 1
            if n == 3:
                return 2
            if (n-2) % 3 == 0:
                return 3**((n-2)/3)*2
            if (n-3) % 3 == 0:
                return 3**((n-3)/3)*3
            if (n-4) % 3 == 0:
                return 3**((n-4)/3)*4

Log in to reply
 

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