python dp soluton 90+


  • 0
    F
    def integerBreak(self, n):
            """
            :type n: int
            :rtype: int
            """
            d = [1] * (n+1)
            if n == 2:
                return 1
            if n == 3:
                return 2
            d[2] = 2
            d[3] = 3
            if n in d and d[n] != 1:
                return d[n]
            for i in range(4,n+1):
                d[i] = 1
                for j in range(1, (i/2)+1):
                    d[i] = max(d[i], d[j]*d[i-j])
            print(d)
            return d[n]
    
    
    

Log in to reply
 

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