We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 16aea1a commit d684943Copy full SHA for d684943
solution/0918.Maximum Sum Circular Subarray/Solution.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int maxSubarraySumCircular(int[] A) {
3
+ int tot = 0;
4
+ int curMax = 0;
5
+ int maxSum = Integer.MIN_VALUE;
6
+ int curMin = 0;
7
+ int minSum = Integer.MAX_VALUE;
8
+ for (int x : A) {
9
+ tot += x;
10
+ curMax = Math.max(curMax + x, x);
11
+ maxSum = Math.max(maxSum, curMax);
12
+ curMin = Math.min(curMin + x, x);
13
+ minSum = Math.min(minSum, curMin);
14
+ }
15
+ return maxSum > 0 ? Math.max(maxSum, tot - minSum) : maxSum;
16
17
+}
0 commit comments