Skip to content

Commit b922bb5

Browse files
committed
Time: 0 ms (100%), Space: 45 MB (97.17%) - LeetHub
1 parent ea48407 commit b922bb5

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -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+
for (int i = 0; i < n; i++) {
14+
temp += nums[i];
15+
if (temp < 0) temp = 0;
16+
ans = max(ans, temp);
17+
}
18+
return ans;
19+
}
20+
};

0 commit comments

Comments
 (0)