A simple bottom up DP in Python


  • 1
    L
    class Solution:
        # @param A, a list of integers
        # @return an integer
        def maxProduct(self, A):
            max_product = front_max = front_min = A[0]
            for i in xrange(1, len(A)):
                front_max, front_min = max(A[i], A[i]*front_max, A[i]*front_min), min(A[i], A[i]*front_max, A[i]*front_min)
                max_product = max(max_product, front_max, front_min)
            return max_product

Log in to reply
 

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