1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/最大相等频率 [maximum-equal-frequency].html
2022-03-29 12:43:11 +08:00

34 lines
1.1 KiB
HTML
Raw 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>,请你帮忙从该数组中找出能满足下面要求的 <strong>最长</strong> 前缀,并返回该前缀的长度:</p>
<ul>
<li>从前缀中 <strong>恰好删除一个</strong> 元素后,剩下每个数字的出现次数都相同。</li>
</ul>
<p>如果删除这个元素后没有剩余元素存在,仍可认为每个数字都具有相同的出现次数(也就是 0 次)。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [2,2,1,1,5,3,3,5]
<strong>输出:</strong>7
<strong>解释:</strong>对于长度为 7 的子数组 [2,2,1,1,5,3,3],如果我们从中删去 nums[4] = 5就可以得到 [2,2,1,1,3,3],里面每个数字都出现了两次。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,1,1,2,2,2,3,3,3,4,4,4,5]
<strong>输出:</strong>13
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>2 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>5</sup></code></li>
</ul>