152. Maximum Product Subarray [M
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
网友评论