8000 Time: 0 ms (100%), Space: 45.2 MB (20.65%) - LeetHub · karygauss03/Leetcode-Solutions@9e62293 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e62293

Browse files
committed
Time: 0 ms (100%), Space: 45.2 MB (20.65%) - LeetHub
1 parent e5a1688 commit 9e62293

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Solution {
2+
public:
3+
int maxAbsoluteSum(vector<int>& nums) {
4+
int n = nums.size();
5+
int mx = INT_MIN, mn = INT_MAX, cur_mx = 0, cur_mn = 0;
6+
for (int i = 0 ; i < n ; i++){
7+
cur_mx += nums[i];
8+
if (cur_mx > mx){
9+
mx = cur_mx;
10+
}
11+
if (cur_mx < 0){
12+
cur_mx = 0;
13+
}
14+
}
15+
16+
for (int i = 0 ; i < n ; i++){
17+
cur_mn += nums[i];
18+
if (cur_mn < mn){
19+
mn = cur_mn;
20+
}
21+
if (cur_mn > 0){
22+
cur_mn = 0;
23+
}
24+
}
25+
return max(abs(mx), abs(mn));
26+
}
27+
};

0 commit comments

Comments
 (0)
0