blob: 57e8cf2516d8b643f44e9563edc3e4f0cb7e790d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# 3005. Count Elements With Maximum Frequency
"""
given an array 'nums' consisting of positive integers. return the total
frequencies of elements in 'nums' such that those elements all have the
maximum frequency. the frequency of an element is the number of occurences of
that in the array
"""
class Solution(object):
def maxFrequencyElements(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
freq = [0] * 101
max_freq, ans = 0, 0
for i in nums:
freq[i] += 1
max_freq = max(max_freq, freq[i])
for i in freq:
if i == max_freq:
ans += i
return ans
if __name__ == "__main__":
obj = Solution()
print(obj.maxFrequencyElements([1, 2, 2, 3, 1, 4]))
print(obj.maxFrequencyElements([1, 2, 3, 4, 5]))
|