原题题目
代码实现(首刷看了点思路)
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
long tempsum = 0;
int ret = 0;
sort(nums.begin(),nums.end());
for(int l=0,r=0;l<nums.size();++l)
{
while(r<nums.size()-1 && tempsum <= k)
{
tempsum += (long long)(nums[r+1] - nums[r])*(r-l+1);
++r;
}
if(tempsum <= k) ret = max(ret,r-l+1);
else ret = max(ret,r-l);
tempsum -= (nums[r] - nums[l]);
}
return ret;
}
};