forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 1749.Maximum-Absolute-Sum-of-Any-Subarray_v1.cpp
- Loading branch information
1 parent
dc2904e
commit 4c973ae
Showing
1 changed file
with
16 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...749.Maximum-Absolute-Sum-of-Any-Subarray/1749.Maximum-Absolute-Sum-of-Any-Subarray_v1.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |