mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			53 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<p>在整数数组中,如果一个整数的出现频次和它的数值大小相等,我们就称这个整数为「幸运数」。</p>
 | 
						||
 | 
						||
<p>给你一个整数数组 <code>arr</code>,请你从中找出并返回一个幸运数。</p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li>如果数组中存在多个幸运数,只需返回 <strong>最大</strong> 的那个。</li>
 | 
						||
	<li>如果数组中不含幸运数,则返回 <strong>-1 </strong>。</li>
 | 
						||
</ul>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>示例 1:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [2,2,3,4]
 | 
						||
<strong>输出:</strong>2
 | 
						||
<strong>解释:</strong>数组中唯一的幸运数是 2 ,因为数值 2 的出现频次也是 2 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 2:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [1,2,2,3,3,3]
 | 
						||
<strong>输出:</strong>3
 | 
						||
<strong>解释:</strong>1、2 以及 3 都是幸运数,只需要返回其中最大的 3 。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 3:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [2,2,2,3,3]
 | 
						||
<strong>输出:</strong>-1
 | 
						||
<strong>解释:</strong>数组中不存在幸运数。
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 4:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [5]
 | 
						||
<strong>输出:</strong>-1
 | 
						||
</pre>
 | 
						||
 | 
						||
<p><strong>示例 5:</strong></p>
 | 
						||
 | 
						||
<pre><strong>输入:</strong>arr = [7,7,7,7,7,7,7]
 | 
						||
<strong>输出:</strong>7
 | 
						||
</pre>
 | 
						||
 | 
						||
<p> </p>
 | 
						||
 | 
						||
<p><strong>提示:</strong></p>
 | 
						||
 | 
						||
<ul>
 | 
						||
	<li><code>1 <= arr.length <= 500</code></li>
 | 
						||
	<li><code>1 <= arr[i] <= 500</code></li>
 | 
						||
</ul>
 |