1746. Maximum Subarray Sum After One Operation
On This Page
class Solution:
def maxSumAfterOperation(self, nums: List[int]) -> int:
f = g = 0
res = -inf
for x in nums:
ff = max(f, 0) + x
gg = max(max(f, 0) + x * x, g + x)
f, g = ff, gg
res = max(res, f, g)
return res