java.lang.Object
g1701_1800.s1749_maximum_absolute_sum_of_any_subarray.Solution

public class Solution extends Object
1749 - Maximum Absolute Sum of Any Subarray.<p>Medium</p> <p>You are given an integer array <code>nums</code>. The <strong>absolute sum</strong> of a subarray <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, &hellip;, nums<sub>r-1</sub>, nums<sub>r</sub>]</code> is <code>abs(nums<sub>l</sub> + nums<sub>l+1</sub> + &hellip; + nums<sub>r-1</sub> + nums<sub>r</sub>)</code>.</p> <p>Return <em>the <strong>maximum</strong> absolute sum of any <strong>(possibly empty)</strong> subarray of</em> <code>nums</code>.</p> <p>Note that <code>abs(x)</code> is defined as follows:</p> <ul> <li>If <code>x</code> is a negative integer, then <code>abs(x) = -x</code>.</li> <li>If <code>x</code> is a non-negative integer, then <code>abs(x) = x</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,-3,2,3,-4]</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong> The subarray [2,3] has absolute sum = abs(2+3) = abs(5) = 5.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [2,-5,1,-4,3,-2]</p> <p><strong>Output:</strong> 8</p> <p><strong>Explanation:</strong> The subarray [-5,1,-4] has absolute sum = abs(-5+1-4) = abs(-8) = 8.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxAbsoluteSum

      public int maxAbsoluteSum(int[] nums)