반응형
https://leetcode.com/problems/count-elements-with-maximum-frequency
class Solution {
public:
int maxFrequencyElements(vector<int>& nums) {
int cnt[101] = {0}, mx = 0, res = 0;
for(int num : nums) mx = max(mx, ++cnt[num]);
for(int i=1; i<101; i++)
if(cnt[i] == mx) res += mx;
return res;
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 238. Product of Array Except Self (1) | 2024.03.16 |
---|---|
LeetCode 349. Intersection of Two Arrays (0) | 2024.03.10 |
LeetCode 876. Middle of the Linked List (0) | 2024.03.07 |
LeetCode 141. Linked List Cycle (1) | 2024.03.07 |
LeetCode 19. Remove Nth Node From End of List (0) | 2024.03.03 |