1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-25 17:50:26 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/统计数组中的美丽分割 [count-beautiful-splits-in-an-array].html
2024-12-20 00:35:26 +08:00

55 lines
2.1 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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>给你一个整数数组&nbsp;<code>nums</code>&nbsp;</p>
<p>如果数组&nbsp;<code>nums</code>&nbsp;的一个分割满足以下条件,我们称它是一个 <strong>美丽</strong>&nbsp;分割:</p>
<ol>
<li>数组&nbsp;<code>nums</code>&nbsp;分为三段 <span data-keyword="subarray-nonempty">非空子数组</span><code>nums1</code>&nbsp;<code>nums2</code>&nbsp;&nbsp;<code>nums3</code>&nbsp;,三个数组&nbsp;<code>nums1</code>&nbsp;<code>nums2</code>&nbsp;&nbsp;<code>nums3</code>&nbsp;按顺序连接可以得到 <code>nums</code>&nbsp;</li>
<li>子数组&nbsp;<code>nums1</code>&nbsp;是子数组&nbsp;<code>nums2</code>&nbsp;<span data-keyword="array-prefix">前缀</span> <strong>或者</strong>&nbsp;<code>nums2</code>&nbsp;&nbsp;<code>nums3</code>&nbsp;<span data-keyword="array-prefix">前缀</span></li>
</ol>
<p>请你返回满足以上条件的分割 <strong>数目</strong>&nbsp;</p>
<p><strong>子数组</strong>&nbsp;指的是一个数组里一段连续 <strong>非空</strong>&nbsp;的元素。</p>
<p><strong>前缀</strong>&nbsp;指的是一个数组从头开始到中间某个元素结束的子数组。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,1,2,1]</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><b>解释:</b></p>
<p>美丽分割如下:</p>
<ol>
<li><code>nums1 = [1]</code>&nbsp;<code>nums2 = [1,2]</code>&nbsp;<code>nums3 = [1]</code>&nbsp;</li>
<li><code>nums1 = [1]</code>&nbsp;<code>nums2 = [1]</code>&nbsp;<code>nums3 = [2,1]</code>&nbsp;</li>
</ol>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [1,2,3,4]</span></p>
<p><span class="example-io"><b>输出:</b>0</span></p>
<p><strong>解释:</strong></p>
<p>没有美丽分割。</p>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 5000</code></li>
<li><code><font face="monospace">0 &lt;= nums[i] &lt;= 50</font></code></li>
</ul>