본문 바로가기

IT/코딩테스트

[Leetcode] 3005. Count Elements With Maximum Frequency

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