class Solution:
def maxFrequencyElements(self, nums: List[int]) -> int:
# let n = lenght of nums
# 1. count frequencies of nums, O(n)
# 2. find out maximum frequency, O(n)
# 3. count the number of max freqs from (#2) and sum up, O(n)
# Time Complexity: O(n)
# Space Complexity: O(n)
cnt = Counter(nums)
max_freq = max(cnt.values())
return sum(cnt[x] for x in cnt if cnt[x] == max_freq)
Python
복사