1911. Maximum Alternating Subsequence Sum

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1911

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