classSolution(object):defmaxProduct(self,nums):""" :type nums: List[int] :rtype: int """pos=[]# positive result arrayneg=[]# negative result arraypos.append(nums[0])neg.append(nums[0])foriinrange(1,len(nums)):pos.append(max(pos[i-1]*nums[i],neg[i-1]*nums[i],nums[i]))neg.append(min(pos[i-1]*nums[i],neg[i-1]*nums[i],nums[i]))# find the largest in pos arrayret=pos[0]foriinpos:ifret<i:ret=ireturnret