Skip to content

Commit

Permalink
Create 1749.Maximum-Absolute-Sum-of-Any-Subarray_v1.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
wisdompeak authored Feb 7, 2021
1 parent dc2904e commit 4c973ae
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
int maxAbsoluteSum(vector<int>& nums)
{
int mx = 0, mn = 0;
int ret = 0;
for (int x: nums)
{
mx = max(mx + x, x);
mn = min(mn + x, x);
ret = max(ret, abs(mx));
ret = max(ret, abs(mn));
}
return ret;
}
};

0 comments on commit 4c973ae

Please sign in to comment.