2404. Most Frequent Even Element

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 2404

class Solution:
    def mostFrequentEven(self, nums: List[int]) -> int:
        cnt = Counter(x for x in nums if x % 2 == 0)
        res, mx = -1, 0
        for x, v in cnt.items():
            if v > mx or (v == mx and res > x):
                res, mx = x, v
        return res