Dorothydu's picture
Add files using upload-large-folder tool
e345cd9 verified
raw
history blame contribute delete
398 Bytes
package main
func maxSlidingWindow(nums []int, k int) []int {
var window, res []int
for i := 0; i < len(nums); i++ {
if len(window) > 0 && window[0] <= i-k {
window = window[1:]
}
for len(window) > 0 && nums[window[len(window)-1]] < nums[i] {
window = window[:len(window)-1]
}
window = append(window, i)
if i >= k-1 {
res = append(res, nums[window[0]])
}
}
return res
}