1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-10-13 01:15:14 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
2025-09-29 14:43:44 +08:00
parent 2862a227c4
commit 13f2098086
4409 changed files with 168933 additions and 166256 deletions

View File

@@ -1,6 +1,6 @@
<p>如果元素 <code>x</code>&nbsp;在长度为 <code>m</code>&nbsp;的整数数组 <code>arr</code>&nbsp;满足 <code>freq(x) * 2 &gt; m</code>&nbsp;,那么我们称 <code>x</code>&nbsp; <strong>支配元素</strong>&nbsp;。其中&nbsp;<code>freq(x)</code>&nbsp;<code>x</code>&nbsp;在数组 <code>arr</code>&nbsp;中出现的次数。注意,根据这个定义,数组 <code>arr</code>&nbsp;<strong>最多</strong>&nbsp;只会有 <strong>一个</strong>&nbsp;支配元素</p>
<p>如果在长度为 <code>m</code>&nbsp;的整数数组 <code>arr</code>&nbsp;<strong>超过一半</strong> 的元素值为&nbsp;<code>x</code>,那么我们称 <code>x</code>&nbsp; <strong>支配元素</strong>&nbsp;</p>
<p>给你一个下标从 <strong>0</strong>&nbsp;开始长度为 <code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;,数据保证它含有一个支配元素。</p>
<p>给你一个下标从 <strong>0</strong>&nbsp;开始长度为 <code>n</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;,数据保证它含有一个 <strong>支配</strong> 元素。</p>
<p>你需要在下标 <code>i</code>&nbsp;处将&nbsp;<code>nums</code>&nbsp;分割成两个数组&nbsp;<code>nums[0, ..., i]</code>&nbsp;<code>nums[i + 1, ..., n - 1]</code>&nbsp;,如果一个分割满足以下条件,我们称它是&nbsp;<strong>合法</strong>&nbsp;的:</p>
@@ -17,7 +17,8 @@
<p><strong>示例 1</strong></p>
<pre><b>输入:</b>nums = [1,2,2,2]
<pre>
<b>输入:</b>nums = [1,2,2,2]
<b>输出:</b>2
<b>解释:</b>我们将数组在下标 2 处分割,得到 [1,2,2] 和 [2] 。
数组 [1,2,2] 中,元素 2 是支配元素,因为它在数组中出现了 2 次,且 2 * 2 &gt; 3 。
@@ -27,7 +28,8 @@
<p><strong>示例 2</strong></p>
<pre><b>输入:</b>nums = [2,1,3,1,1,1,7,1,2,1]
<pre>
<b>输入:</b>nums = [2,1,3,1,1,1,7,1,2,1]
<b>输出:</b>4
<b>解释:</b>我们将数组在下标 4 处分割,得到 [2,1,3,1,1] 和 [1,7,1,2,1] 。
数组 [2,1,3,1,1] 中,元素 1 是支配元素,因为它在数组中出现了 3 次,且 3 * 2 &gt; 5 。
@@ -37,7 +39,8 @@
<p><strong>示例 3</strong></p>
<pre><b>输入:</b>nums = [3,3,3,3,7,2,2]
<pre>
<b>输入:</b>nums = [3,3,3,3,7,2,2]
<b>输出:</b>-1
<b>解释:</b>没有合法分割。
</pre>