Class Solution
java.lang.Object
g1301_1400.s1394_find_lucky_integer_in_an_array.Solution
1394 - Find Lucky Integer in an Array.<p>Easy</p>
<p>Given an array of integers <code>arr</code>, a <strong>lucky integer</strong> is an integer that has a frequency in the array equal to its value.</p>
<p>Return <em>the largest <strong>lucky integer</strong> in the array</em>. If there is no <strong>lucky integer</strong> return <code>-1</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> arr = [2,2,3,4]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The only lucky number in the array is 2 because frequency[2] == 2.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> arr = [1,2,2,3,3,3]</p>
<p><strong>Output:</strong> 3</p>
<p><strong>Explanation:</strong> 1, 2 and 3 are all lucky numbers, return the largest of them.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> arr = [2,2,2,3,3]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> There are no lucky numbers in the array.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= arr.length <= 500</code></li>
<li><code>1 <= arr[i] <= 500</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findLucky
public int findLucky(int[] arr)
-