Skip to content

Commit c446d0d

Browse files
committed
Solution as on 05-04-2022 08:25 pm
1 parent e9ffaa6 commit c446d0d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// 1749.✅ Maximum Absolute Sum of Any Subarray
2+
3+
class Solution
4+
{
5+
public:
6+
int maxAbsoluteSum(vector<int> &nums)
7+
{
8+
int sum1 = 0, sum2 = 0;
9+
int mx = 0, mn = 0;
10+
for (int i = 0; i < nums.size(); ++i)
11+
{
12+
sum1 += nums[i];
13+
if (sum1 < 0)
14+
sum1 = 0;
15+
mx = max(mx, sum1);
16+
}
17+
for (int i = 0; i < nums.size(); ++i)
18+
{
19+
sum2 += nums[i];
20+
if (sum2 > 0)
21+
sum2 = 0;
22+
mn = min(mn, sum2);
23+
}
24+
return max(mx, abs(mn));
25+
}
26+
};

0 commit comments

Comments
 (0)