1749. Maximum Absolute Sum of Any Subarray

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

Содержание

LeetCode problem 1749

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