Skip to content

Commit

Permalink
Time: 66 ms (87.53%), Space: 40 MB (38.25%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipendra-Raghav committed Jan 18, 2023
1 parent 8b93b04 commit 0bcf885
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution {
public:
int maxSubarraySumCircular(vector<int>& nums) {
int totalSum = 0, maxSum = INT_MIN, curMax = 0, minSum = INT_MAX, curMin = 0;
for (int x : nums) {
curMax = max(x, curMax + x);
maxSum = max(maxSum, curMax);
curMin = min(x, curMin + x);
minSum = min(minSum, curMin);
totalSum += x;
}
return maxSum > 0 ? max(maxSum, totalSum - minSum) : maxSum;
}
};

0 comments on commit 0bcf885

Please sign in to comment.