1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/执行操作后元素的最高频率 II [maximum-frequency-of-an-element-after-performing-operations-ii].html
2024-11-29 17:49:27 +08:00

59 lines
2.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>&nbsp;和两个整数&nbsp;<code>k</code>&nbsp;<code>numOperations</code>&nbsp;</p>
<p>你必须对 <code>nums</code>&nbsp;执行 <strong>操作</strong>&nbsp; <code>numOperations</code>&nbsp;次。每次操作中,你可以:</p>
<ul>
<li>选择一个下标&nbsp;<code>i</code>&nbsp;,它在之前的操作中 <strong>没有</strong>&nbsp;被选择过。</li>
<li><code>nums[i]</code>&nbsp;增加范围&nbsp;<code>[-k, k]</code>&nbsp;中的一个整数。</li>
</ul>
<p>在执行完所有操作以后,请你返回 <code>nums</code>&nbsp;中出现 <strong>频率最高</strong>&nbsp;元素的出现次数。</p>
<p>一个元素 <code>x</code>&nbsp;<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,4,5], k = 1, numOperations = 2</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p>通过以下操作得到最高频率 2 </p>
<ul>
<li>&nbsp;<code>nums[1]</code>&nbsp;增加 0 <code>nums</code> 变为&nbsp;<code>[1, 4, 5]</code>&nbsp;</li>
<li>&nbsp;<code>nums[2]</code>&nbsp;增加 -1 <code>nums</code> 变为&nbsp;<code>[1, 4, 4]</code>&nbsp;</li>
</ul>
</div>
<p><strong class="example">示例 2</strong></p>
<div class="example-block">
<p><span class="example-io"><b>输入:</b>nums = [5,11,20,20], k = 5, numOperations = 1</span></p>
<p><span class="example-io"><b>输出:</b>2</span></p>
<p><strong>解释:</strong></p>
<p>通过以下操作得到最高频率 2 </p>
<ul>
<li>&nbsp;<code>nums[1]</code>&nbsp;增加 0 。</li>
</ul>
</div>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= k &lt;= 10<sup>9</sup></code></li>
<li><code>0 &lt;= numOperations &lt;= nums.length</code></li>
</ul>