mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-10-13 01:15:14 +08:00
update
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<p>如果元素 <code>x</code> 在长度为 <code>m</code> 的整数数组 <code>arr</code> 中满足 <code>freq(x) * 2 > m</code> ,那么我们称 <code>x</code> 是 <strong>支配元素</strong> 。其中 <code>freq(x)</code> 是 <code>x</code> 在数组 <code>arr</code> 中出现的次数。注意,根据这个定义,数组 <code>arr</code> <strong>最多</strong> 只会有 <strong>一个</strong> 支配元素。</p>
|
||||
<p>如果在长度为 <code>m</code> 的整数数组 <code>arr</code> 中 <strong>超过一半</strong> 的元素值为 <code>x</code>,那么我们称 <code>x</code> 是 <strong>支配元素</strong> 。</p>
|
||||
|
||||
<p>给你一个下标从 <strong>0</strong> 开始长度为 <code>n</code> 的整数数组 <code>nums</code> ,数据保证它含有一个支配元素。</p>
|
||||
<p>给你一个下标从 <strong>0</strong> 开始长度为 <code>n</code> 的整数数组 <code>nums</code> ,数据保证它含有一个 <strong>支配</strong> 元素。</p>
|
||||
|
||||
<p>你需要在下标 <code>i</code> 处将 <code>nums</code> 分割成两个数组 <code>nums[0, ..., i]</code> 和 <code>nums[i + 1, ..., n - 1]</code> ,如果一个分割满足以下条件,我们称它是 <strong>合法</strong> 的:</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 > 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 > 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>
|
||||
|
Reference in New Issue
Block a user