mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-04 15:01:40 +08:00
66 lines
3.3 KiB
HTML
66 lines
3.3 KiB
HTML
<p data-end="365" data-start="23">给你一个长度为 <code data-end="76" data-start="73">n</code> 的整数数组 <code data-end="62" data-start="54">weight</code>,表示按直线排列的 <code data-end="109" data-start="106">n</code> 个包裹的重量。<b>装运</b> 定义为包裹的一个连续子数组。如果一个装运满足以下条件,则称其为 <strong data-end="247" data-start="235">平衡装运</strong>:<strong data-end="284" data-start="269">最后一个包裹的重量</strong> <strong>严格小于 </strong>该装运中所有包裹中 <strong data-end="329" data-start="311">最大重量 </strong>。</p>
|
||
|
||
<p data-end="528" data-start="371">选择若干个 <strong data-end="406" data-start="387">不重叠 </strong>的连续平衡装运,并满足 <strong data-end="496" data-start="449">每个包裹最多出现在一次装运中</strong>(部分包裹可以不被装运)。</p>
|
||
|
||
<p data-end="587" data-start="507">返回 <strong data-end="545" data-start="518">可以形成的平衡装运的最大数量 </strong>。</p>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong class="example">示例 1:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong> <span class="example-io">weight = [2,5,1,4,3]</span></p>
|
||
|
||
<p><strong>输出:</strong> <span class="example-io">2</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p data-end="136" data-start="62">我们可以形成最多两个平衡装运:</p>
|
||
|
||
<ul>
|
||
<li data-end="163" data-start="140">装运 1: <code>[2, 5, 1]</code>
|
||
|
||
<ul>
|
||
<li data-end="195" data-start="168">包裹的最大重量 = 5</li>
|
||
<li data-end="275" data-start="200">最后一个包裹的重量 = 1,严格小于 5,因此这是平衡装运。</li>
|
||
</ul>
|
||
</li>
|
||
<li data-end="299" data-start="279">装运 2: <code>[4, 3]</code>
|
||
<ul>
|
||
<li data-end="331" data-start="304">包裹的最大重量 = 4</li>
|
||
<li data-end="411" data-start="336">最后一个包裹的重量 = 3,严格小于 4,因此这是平衡装运。</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<p data-end="519" data-start="413">无法通过其他方式划分包裹获得超过两个平衡装运,因此答案是 2。</p>
|
||
</div>
|
||
|
||
<p><strong class="example">示例 2:</strong></p>
|
||
|
||
<div class="example-block">
|
||
<p><strong>输入:</strong> <span class="example-io">weight = [4,4]</span></p>
|
||
|
||
<p><strong>输出:</strong> <span class="example-io">0</span></p>
|
||
|
||
<p><strong>解释:</strong></p>
|
||
|
||
<p data-end="635" data-start="574">在这种情况下无法形成平衡装运:</p>
|
||
|
||
<ul>
|
||
<li data-end="772" data-start="639">装运 <code>[4, 4]</code> 的最大重量为 4,而最后一个包裹的重量也是 4,不严格小于最大重量,因此不是平衡的。</li>
|
||
<li data-end="885" data-start="775">单个包裹的装运 <code>[4]</code> 中,最后一个包裹的重量等于最大重量,因此也不是平衡的。</li>
|
||
</ul>
|
||
|
||
<p data-end="958" data-is-last-node="" data-is-only-node="" data-start="887">由于无法形成任何平衡装运,答案是 0。</p>
|
||
</div>
|
||
|
||
<p> </p>
|
||
|
||
<p><strong>提示:</strong></p>
|
||
|
||
<ul>
|
||
<li data-end="8706" data-start="8671"><code data-end="8704" data-start="8671">2 <= n <= 10<sup>5</sup></code></li>
|
||
<li data-end="8733" data-start="8709"><code data-end="8733" data-start="8709">1 <= weight[i] <= 10<sup>9</sup></code></li>
|
||
</ul>
|