funcmaxFrequency(nums []int, k int)int { sort.Ints(nums) start,sum := 0,0 ans := 1 for i := 1; i < len(nums); i++ { //计算差值 //1,2,5 (2-1)*1+(5-2)*2=7. //此处需要多想一下 sum += (nums[i] - nums[i-1]) * (i - start) for sum > k { sum -= nums[i] - nums[start] start++