-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
26 lines (23 loc) · 854 Bytes
/
main.py
File metadata and controls
26 lines (23 loc) · 854 Bytes
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
class Solution(object):
def maxFrequencyElements(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
# Find the frequency of each element
frequencies = {}
for num in nums:
if num in frequencies:
frequencies[num] += 1
else:
frequencies[num] = 1
# Determine the maximum frequency
max_frequency = 0
for frequency in frequencies.values():
max_frequency = max(max_frequency, frequency)
# Calculate the total frequencies of elements with the maximum frequency
frequency_of_max_frequency = 0
for frequency in frequencies.values():
if frequency == max_frequency:
frequency_of_max_frequency += 1
return frequency_of_max_frequency * max_frequency