918. Maximum Sum Circular Subarray (kadane-algo)
Last updated
Was this helpful?
Last updated
Was this helpful?
case1: noneCircularMaxSum
case2: circularMaxSum
corner case, all numbers are negative, minSum = total, so total - minsum = 0
result will be wrong : max(maxSum, 0) = 0, but we should return maxSum,
so when total - minsum = 0 (circularMaxSum == 0), just return maxSum (noneCircularMaxSum)
T: O(n)
S: O(1)