2036. Maximum Alternating Subarray Sum

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2036

class Solution:
    def maximumAlternatingSubarraySum(self, nums: List[int]) -> int:
        res = f = g = -inf
        for x in nums:
            f, g = max(g, 0) + x, f - x
            res = max(res, f, g)
        return res