Search

2024-03-08 Leetcode Daily Problem

생성일
2024/03/08 11:08
태그
알고리즘
날짜
2024/03/08
3 more properties
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
복사