Skip to content

Commit b81d6ed

Browse files
committed
feat: Solve maximum-product-subarray problem
1 parent e43f14a commit b81d6ed

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

maximum-product-subarray/hu6r1s.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def maxProduct(self, nums: List[int]) -> int:
3+
result = nums[0]
4+
min_prod = max_prod = 1
5+
for num in nums:
6+
min_prod, max_prod = min(min_prod * num, max_prod * num, num), max(min_prod * num, max_prod * num, num)
7+
result = max(max_prod, result)
8+
return result

0 commit comments

Comments
 (0)