728x90
https://leetcode.com/problems/count-elements-with-maximum-frequency
class Solution:
def maxFrequencyElements(self, nums: List[int]) -> int:
frequency = {}
unique = list(set(nums))
for n in unique:
count = nums.count(n)
if frequency.get(count, None) is None:
frequency[count] = 1
else:
frequency[count] += 1
max_f = max(frequency.keys())
return max_f * frequency[max_f]
728x90
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 349. Intersection of Two Arrays (0) | 2024.03.10 |
---|---|
[Leetcode] 2540. Minimum Common Value (0) | 2024.03.09 |
[Leetcode] 2864. Maximum Odd Binary Number (0) | 2024.03.08 |
[Leetcode] 876. Middle of the Linked List (0) | 2024.03.07 |
[Leetcode] 961. N-Repeated Element in Size 2N Array (0) | 2024.03.07 |