19 lines
326 B
Go
19 lines
326 B
Go
package maximum_sliding_window
|
|
|
|
import (
|
|
"git.maximhutz.com/practice/pkg/tools/heap"
|
|
)
|
|
|
|
func MaxSlidingWindow(nums []int, k int) []int {
|
|
h := heap.NewBy(heap.More, nums[:k]...)
|
|
result := []int{h.Top()}
|
|
|
|
for i := range nums[k:] {
|
|
h.Drop(nums[i])
|
|
h.Put(nums[i+k])
|
|
result = append(result, h.Top())
|
|
}
|
|
|
|
return result
|
|
}
|