题目
https://leetcode-cn.com/problems/frequency-of-the-most-frequent-element/
代码
class Solution {
public int maxFrequency(int[] nums, int k) {
int len=nums.length;
if(len==0) return 0;
Arrays.sort(nums);
int total=0;
int left=0;
int right=1;
int res=1;
for(right=1;right<len;right++){
total+=(nums[right]-nums[right-1])*(right-left);
while(total>k){
total-=nums[right]-nums[left];
left++;
}
res=Math.max(res,right-left+1);
}
return res;
}
}