Участник:Kiranov dmitry/task1

Материал из DISCOPAL
Перейти к: навигация, поиск

ссылка: https://leetcode.com/problems/maximum-product-subarray/

class Solution:
    def maxProduct(self, nums):
        b = nums
        a = []
        i = 0
        while i < (len(b)):
            if (b[i] != '[') and (b[i] != ',') and (b[i] != ' ') and (b[i] != ']'):
                if b[i] == '-':
                    i += 1 
                    a.append(-int(b[i]))
                else:
                    a.append(int(b[i]))
            i += 1
        positive = a[0]
        negative = a[0]
        res = a[0]
        for x in a[1:]:
            y = x*positive
            positive = max(x, y, x*negative)
            negative = min(x, x*negative, y)
            res = max(positive, res)
        return res