| 1 | class 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 | |
| 15 | print(Solution().maxProduct([-3,-1,-1])) |
| 16 | print(Solution().maxProduct([2,3,-2,4])) |
no outgoing calls
no test coverage detected