MCPcopy Create free account
hub / github.com/Sugapriyan-P-K/blind75 / Solution

Class Solution

Arrays/6maximumProductSubarray/maximumProductSubarray.py:1–13  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution:
2 def maxProduct(self, nums: list[int]) -> int:
3 res = max(nums)
4 currMin, currMax = 1, 1
5 for n in nums:
6 if n == 0:
7 currMax, currMin = 1, 1
8 continue
9 tmp = currMax * n
10 currMax = max(n * currMax , n * currMin, n)
11 currMin = min(tmp, n * currMin, n)
12 res = max(res, currMax)
13 return res
14
15print(Solution().maxProduct([-3,-1,-1]))
16print(Solution().maxProduct([2,3,-2,4]))

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected