mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 03:33:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>元素的 <strong>频数</strong> 是该元素在一个数组中出现的次数。</p>
 | 
						||
 | 
						||
<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>k</code> 。在一步操作中,你可以选择 <code>nums</code> 的一个下标,并将该下标对应元素的值增加 <code>1</code> 。</p>
 | 
						||
 | 
						||
<p>执行最多 <code>k</code> 次操作后,返回数组中最高频元素的 <strong>最大可能频数</strong> <em>。</em></p>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [1,2,4], k = 5
 | 
						||
<strong>输出:</strong>3<strong>
 | 
						||
解释:</strong>对第一个元素执行 3 次递增操作,对第二个元素执 2 次递增操作,此时 nums = [4,4,4] 。
 | 
						||
4 是数组中最高频元素,频数是 3 。</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [1,4,8,13], k = 5
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>存在多种最优解决方案:
 | 
						||
- 对第一个元素执行 3 次递增操作,此时 nums = [4,4,8,13] 。4 是数组中最高频元素,频数是 2 。
 | 
						||
- 对第二个元素执行 4 次递增操作,此时 nums = [1,8,8,13] 。8 是数组中最高频元素,频数是 2 。
 | 
						||
- 对第三个元素执行 5 次递增操作,此时 nums = [1,4,13,13] 。13 是数组中最高频元素,频数是 2 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre>
 | 
						||
<strong>输入:</strong>nums = [3,9,6], k = 2
 | 
						||
<strong>输出:</strong>1
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
 | 
						||
	<li><code>1 <= nums[i] <= 10<sup>5</sup></code></li>
 | 
						||
	<li><code>1 <= k <= 10<sup>5</sup></code></li>
 | 
						||
</ul>
 |