美文网首页
152. Maximum Product Subarray [M

152. Maximum Product Subarray [M

作者: 一个想当大佬的菜鸡 | 来源:发表于2019-06-11 23:27 被阅读0次

152. Maximum Product Subarray

152. Maximum Product Subarray
class Solution(object):
    def maxProduct(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) == 0:
            return None
        Max, Min = [0] * len(nums), [0] * len(nums)
        res = Max[0] = Min[0] = nums[0]
        for i in range(1, len(nums)):
            Max[i] = max(nums[i], nums[i]*Max[i-1], nums[i]*Min[i-1])
            Min[i] = min(nums[i], nums[i]*Min[i-1], nums[i]*Max[i-1])
            res = max(Max[i], res)
        return res

相关文章

网友评论

      本文标题:152. Maximum Product Subarray [M

      本文链接:https://www.haomeiwen.com/subject/apdhfctx.html