1749. Maximum Absolute Sum of Any Subarray Medium
1/**
2 * [1749] Maximum Absolute Sum of Any Subarray
3 *
4 * You are given an integer array nums. The absolute sum of a subarray [numsl, numsl+1, ..., numsr-1, numsr] is abs(numsl + numsl+1 + ... + numsr-1 + numsr).
5 * Return the maximum absolute sum of any (possibly empty) subarray of nums.
6 * Note that abs(x) is defined as follows:
7 *
8 * If x is a negative integer, then abs(x) = -x.
9 * If x is a non-negative integer, then abs(x) = x.
10 *
11 *
12 * Example 1:
13 *
14 * Input: nums = [1,-3,2,3,-4]
15 * Output: 5
16 * Explanation: The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.
17 *
18 * Example 2:
19 *
20 * Input: nums = [2,-5,1,-4,3,-2]
21 * Output: 8
22 * Explanation: The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= nums.length <= 10^5
28 * -10^4 <= nums[i] <= 10^4
29 *
30 */
31pub struct Solution {}
32
33// problem: https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/
34// discuss: https://leetcode.com/problems/maximum-absolute-sum-of-any-subarray/discuss/?currentPage=1&orderBy=most_votes&query=
35
36// submission codes start here
37
38impl Solution {
39 pub fn max_absolute_sum(nums: Vec<i32>) -> i32 {
40 0
41 }
42}
43
44// submission codes end
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn test_1749() {
52 }
53}
54
Back
© 2025 bowen.ge All Rights Reserved.