classSolution:defmaximumSum(self,arr: List[int]) ->int: res = arr[0]defmaxSubSum(arr,skip): res = maxSub =float("-inf")for i inrange(len(arr)):if i == skip:continue maxSub =max(arr[i], maxSub + arr[i]) res =max(res, maxSub)return res# 这里循环到了len(arr)项,表示的是一个都不删除的情况for i inrange(len(arr) +1): res =max(res, maxSubSum(arr, i))return res
classSolution:defmaximumSum(self,arr: List[int]) ->int: n =len(arr) l = [arr[0]] * n r = [arr[n -1]] * nif n ==1:return arr[0] res = arr[0]for i inrange(1, n): l[i]=max(l[i -1] + arr[i], arr[i]) res =max(res, l[i])for i inrange(n -2, -1, -1): r[i]=max(r[i +1] + arr[i], arr[i]) res =max(res, r[i])for i inrange(1, n -1): res =max(res, l[i -1] + r[i +1])return res