My python DP solution.


  • 0
    S
    class Solution(object):
        def maxProduct(self, nums):
            """
            :type nums: List[int]
            :rtype: int
            """
            minlist,maxlist = [nums[0]],[nums[0]]
            for i in range(1,len(nums)):
                minlist.append(min(nums[i],minlist[i-1]*nums[i],maxlist[i-1]*nums[i]))
                maxlist.append(max(nums[i],minlist[i-1]*nums[i],maxlist[i-1]*nums[i]))
            return max(maxlist)
    

Log in to reply
 

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