LeetCode---152. Maximum Product Subarray

题目

给出一个整数数组,找到一个连续子序列,该子序列具有最大的乘积。

Python题解

class Solution(object):
    def maxProduct(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        maxnum = big = small = nums[0]
        for n in nums[1:]:
            big, small = max(n, n * big, n * small), min(n, n * big, n * small)
            maxnum = max(maxnum, big)
        return maxnum

猜你喜欢

转载自blog.csdn.net/leel0330/article/details/80496179