2404. Most Frequent Even Element Easy
1/**
2 * [2404] Most Frequent Even Element
3 *
4 * Given an integer array nums, return the most frequent even element.
5 * If there is a tie, return the smallest one. If there is no such element, return -1.
6 *
7 * Example 1:
8 *
9 * Input: nums = [0,1,2,2,4,4,1]
10 * Output: 2
11 * Explanation:
12 * The even elements are 0, 2, and 4. Of these, 2 and 4 appear the most.
13 * We return the smallest one, which is 2.
14 * Example 2:
15 *
16 * Input: nums = [4,4,4,9,2,4]
17 * Output: 4
18 * Explanation: 4 is the even element appears the most.
19 *
20 * Example 3:
21 *
22 * Input: nums = [29,47,21,41,13,37,25,7]
23 * Output: -1
24 * Explanation: There is no even element.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= nums.length <= 2000
30 * 0 <= nums[i] <= 10^5
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/most-frequent-even-element/
36// discuss: https://leetcode.com/problems/most-frequent-even-element/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn most_frequent_even(nums: Vec<i32>) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_2404() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.