leetcode-918 and annular maximum subarray
Subject description:
Given an array of annular array of integers represented by C A, C nonempty seeking the maximum possible and the array. Each subarray can only contain a fixed element of the buffer A in a
head enough
class Solution:
def maxSubarraySumCircular(self, A: List[int]) -> int:
def kadane(nums):
res, cur = float("-inf"), float("-inf")
for v in nums:
cur = max(cur,0) + v
res = max(res,cur)
return res
if max(A)<0:
return max(A)
res1 = kadane(A)
res2 = sum(A) + kadane([-v for v in A])
return max(res1,res2)