1186. Maximum Subarray Sum with One Deletion
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 45% Topics: Array, Dynamic Programming
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
class Solution(object):
def maximumSum(self, arr):
"""
:type arr: List[int]
:rtype: int
"""
result, prev, curr = float("-inf"), float("-inf"), float("-inf")
for x in arr:
curr = max(prev, curr+x, x)
result = max(result, curr)
prev = max(prev+x, x)
return result
Solution from kamyu104/LeetCode-Solutions · MIT