给定一个整数数组  ,找出一个序列中乘积最大的连续子序列的乘积(该序列至少包含一个数)。

区块链毕设网qklbishe.com为您提供问题的解答

给定一个整数数组 ,找出一个序列中乘积最大的连续子序列的乘积(该序列至少包含一个数)。

#

# @param nums int整型一维数组 
# @return int整型
#
class Solution:
    def maxProduct(self , nums ):
        # write code here
        if not nums: return 
        res = nums[0]
        pre_max = nums[0]
        pre_min = nums[0]
        for num in nums[1:]:
            cur_max = max(pre_max * num, pre_min * num, num)
            cur_min = min(pre_max * num, pre_min * num, num)
            res = max(res, cur_max)
            pre_max = cur_max
            pre_min = cur_min
        return res

55:58

以上就是关于问题给定一个整数数组  ,找出一个序列中乘积最大的连续子序列的乘积(该序列至少包含一个数)。的答案

欢迎关注区块链毕设网-
专业区块链毕业设计成品源码,定制。

区块链NFT链游项目方科学家脚本开发培训

承接区块链项目定制开发

微信:btc9767

QQ :1330797917

TELEGRAM: BTCOK9

承接区块链项目定制开发


qklbishe.com区块链毕设代做网专注|以太坊fabric-计算机|java|毕业设计|代做平台-javagopython毕设 » 给定一个整数数组  ,找出一个序列中乘积最大的连续子序列的乘积(该序列至少包含一个数)。