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

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

ссылка: https://leetcode.com/problems/maximum-subarray-sum-with-one-deletion/

class Solution:
    def maximumSum(self, arr):
        b = arr
        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:]:
            positive = max(positive + x, negative)
            negative = max(negative + x, x)
            res = max(positive, negative, res)
        return res