文章目录
题意
思路
计数
代码
C++
class Solution {
public:
int maxFrequencyElements(vector<int>& nums) {
vector<int> v(100, 0);
for (auto &index: nums) {
v[index - 1]++;
}
sort(v.begin(), v.end());
int ans = 0;
int maxTmp = v.back();
for (auto index = v.rbegin(); index != v.rend(); index++)
{
if (*index == maxTmp)
ans += *index;
else
break;
}
return ans;
}
};