1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/任意子数组和的绝对值的最大值 [maximum-absolute-sum-of-any-subarray].html
2022-03-29 12:43:11 +08:00

38 lines
1.3 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组 <code>nums</code> 。一个子数组 <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> 的 <strong>和的绝对值</strong> 为 <code>abs(nums<sub>l</sub> + nums<sub>l+1</sub> + ... + nums<sub>r-1</sub> + nums<sub>r</sub>)</code> 。</p>
<p>请你找出 <code>nums</code> 中 <strong>和的绝对值</strong> 最大的任意子数组(<b>可能为空</b>),并返回该 <strong>最大值</strong> 。</p>
<p><code>abs(x)</code> 定义如下:</p>
<ul>
<li>如果 <code>x</code> 是负整数,那么 <code>abs(x) = -x</code> 。</li>
<li>如果 <code>x</code> 是非负整数,那么 <code>abs(x) = x</code> 。</li>
</ul>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [1,-3,2,3,-4]
<b>输出:</b>5
<b>解释:</b>子数组 [2,3] 和的绝对值最大,为 abs(2+3) = abs(5) = 5 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>nums = [2,-5,1,-4,3,-2]
<b>输出:</b>8
<b>解释:</b>子数组 [-5,1,-4] 和的绝对值最大,为 abs(-5+1-4) = abs(-8) = 8 。
</pre>
<p> </p>
<p><strong>提示:</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>