Skip to content

Commit a3b4539

Browse files
committed
maximum-product-subarray solution
1 parent e66691e commit a3b4539

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

maximum-product-subarray/sun912.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
TC: O(n)
3+
SC: O(1)
4+
"""
5+
class Solution:
6+
def maxProduct(self, nums: List[int]) -> int:
7+
minimum, maximum = 1, 1
8+
result = nums[0]
9+
10+
for num in nums:
11+
minimum, maximum = min(minimum * num, maximum * num, num), max(minimum * num, maximum * num, num)
12+
result = max(maximum, result)
13+
14+
return result
15+

0 commit comments

Comments
 (0)