My python solution (similar to max sum subarray)

  • 0
    def maxProduct(self, nums):
        :type nums: List[int]
        :rtype: int
        if not nums:
            return 0
        curMax = nums[0]
        maxP = nums[0]
        curMin = nums[0]
        for i in nums[1:]:
            tmp = max(i, curMax*i, curMin*i)
            tmp1 = min(i, curMin*i, curMax*i)
            curMax = tmp
            curMin = tmp1
            maxP = max(maxP, curMax)
        return maxP

Log in to reply

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