We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ea48407 commit b922bb5Copy full SHA for b922bb5
1749-maximum-absolute-sum-of-any-subarray/1749-maximum-absolute-sum-of-any-subarray.cpp
@@ -0,0 +1,20 @@
1
+class Solution {
2
+public:
3
+ int maxAbsoluteSum(vector<int>& nums) {
4
+ int ans = 0;
5
+ int n = nums.size();
6
+ int temp = 0;
7
+ for (int i = 0; i < n; i++) {
8
+ temp += nums[i];
9
+ if (temp > 0) temp = 0;
10
+ ans = max(ans, -temp);
11
+ }
12
+ temp = 0;
13
14
15
+ if (temp < 0) temp = 0;
16
+ ans = max(ans, temp);
17
18
+ return ans;
19
20
+};
0 commit comments