LeetCode 152 Maximum Product Subarray

LeetCode 152 Maximum Product Subarray Problem

Download Code
class Solution(object):
    def maxProduct(self, nums):
        :type nums: List[int]
        :rtype: int
        if nums is None or len(nums) == 0:
            return 0
        max_here = min_here = max_so_far = nums[0]
        for i in range(1, len(nums)):
            mx, mn = max_here, min_here
            max_here = max(max(mx * nums[i], nums[i]), mn * nums[i])
            min_here = min(min(mx * nums[i], nums[i]), mn * nums[i])
            max_so_far = max(max_here, max_so_far)
        return max_so_far
Download Maximum Product Subarray.py

List of all Maximum Product Subarray problems

Leetcode 152 Maximum Product Subarray problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.