class Solution:
def maxProduct(self, nums: list[int]) -> int:
result = acc_max = acc_min = nums[0]
for i in range(1, len(nums)):
cand = nums[i], nums[i] * acc_max, nums[i] * acc_min
acc_max, acc_min = max(cand), min(cand)
result = max(result, acc_max, acc_min)
return result
152. Maximum Product Subarray - LeetCode
· One min read