1394. Find Lucky Integer in an Array Easy
1/**
2 * [1394] Find Lucky Integer in an Array
3 *
4 * Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value.
5 * Return the largest lucky integer in the array. If there is no lucky integer return -1.
6 *
7 * Example 1:
8 *
9 * Input: arr = [2,2,3,4]
10 * Output: 2
11 * Explanation: The only lucky number in the array is 2 because frequency[2] == 2.
12 *
13 * Example 2:
14 *
15 * Input: arr = [1,2,2,3,3,3]
16 * Output: 3
17 * Explanation: 1, 2 and 3 are all lucky numbers, return the largest of them.
18 *
19 * Example 3:
20 *
21 * Input: arr = [2,2,2,3,3]
22 * Output: -1
23 * Explanation: There are no lucky numbers in the array.
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= arr.length <= 500
29 * 1 <= arr[i] <= 500
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/find-lucky-integer-in-an-array/
35// discuss: https://leetcode.com/problems/find-lucky-integer-in-an-array/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn find_lucky(arr: Vec<i32>) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1394() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.