Skip to content

Commit e3816c1

Browse files
committed
Feb 26
1 parent 5d7d5e7 commit e3816c1

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def maxAbsoluteSum(self, nums: list[int]) -> int:
3+
max_sum, min_sum = 0, 0
4+
ans = 0
5+
for num in nums:
6+
max_sum = max(max_sum + num, 0)
7+
min_sum = min(min_sum + num, 0)
8+
ans = max(ans, max_sum, -min_sum)
9+
return ans
10+
11+
12+
def main():
13+
nums = [1, -3, 2, 3, -4]
14+
assert Solution().maxAbsoluteSum(nums) == 5
15+
16+
nums = [2, -5, 1, -4, 3, -2]
17+
assert Solution().maxAbsoluteSum(nums) == 8
18+
19+
20+
if __name__ == '__main__':
21+
main()

2025-02-February-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
| February 23 | [889. Construct Binary Tree from Preorder and Postorder Traversal](https://leetcode.com/problems/construct-binary-tree-from-preorder-and-postorder-traversal/) | Medium | Unsolved |
3030
| February 24 | [2467. Most Profitable Path in a Tree](https://leetcode.com/problems/most-profitable-path-in-a-tree/) | Medium | Unsolved |
3131
| February 25 | [1524. Number of Sub-arrays With Odd Sum](https://leetcode.com/problems/number-of-sub-arrays-with-odd-sum/) | Medium | Solved |
32-
| February 26 | []() | | |
32+
| February 26 | [1749. Maximum Absolute Sum of Any Subarray](https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/) | Medium | Unsolved |
3333
| February 27 | []() | | |
3434
| February 28 | []() | | |
3535

@@ -38,5 +38,5 @@
3838
| Level | Problems | Solved | Unsolved |
3939
| --- | --- | --- | --- |
4040
| Easy | 6 | 6 | 0 |
41-
| Medium | 17 | 13 | 4 |
41+
| Medium | 18 | 13 | 5 |
4242
| Hard | 1 | 1 | 0 |

0 commit comments

Comments
 (0)