3005. Count Elements with Maximum Frequency (Python) | Leetcode

preview_player
Показать описание
In this video, I will show you how to solve the leetcode problem number 3005 Count Elements with Maximum Frequency. I will explain the algorithm and then code it in Python. The problem gives you an array. The array consists of only positive integers. The problem wants you to find the number of times each element occurs inside the array. And then you have to determine which of the elements occurs the most.
Рекомендации по теме
Комментарии
Автор

from collections import Counter
nums = [1, 2, 2, 3, 1, 3, 4]
freq = [i for i in Counter(nums).values()]
ans = sum(list(filter(lambda x: x == max(freq), freq)))
print(ans)

CibelColaco
visit shbcf.ru