Skip to content

Commit

Permalink
滑动窗口滑不来啊,有点东西的
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerxiong committed Jul 20, 2021
1 parent 73211ec commit a895c98
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 1838.最高频元素的频数.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* @lc app=leetcode.cn id=1838 lang=golang
*
* [1838] 最高频元素的频数
*/

// @lc code=start
func maxFrequency(nums []int, k int) int {
sort.Ints(nums)

l, r, total := 0, 1, 0
max := 1

for ; r < len(nums); r++ {
total += (nums[r] - nums[r-1]) * (r - l)
for total > k {
total -= nums[r] - nums[l]
l++
}
m := r - l + 1
if m > max {
max = m
}
}
return max
}

// @lc code=end

0 comments on commit a895c98

Please sign in to comment.