You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
func maxSlidingWindow(_ nums: [Int], _ k: Int) -> [Int] {
guard k > 0 && k <= nums.count else {
return []
}
var maxIdx = [Int]()
var res = [Int]()
for i in 0..<nums.count {
while maxIdx.count > 0 && nums[maxIdx.last!] <= nums[i] {
maxIdx.removeLast()
}
maxIdx.append(i)
if i >= k - 1 {
if maxIdx.first! + k == i {
maxIdx.removeFirst()
}
res.append(nums[maxIdx.first!])
}
}
return res
}
The text was updated successfully, but these errors were encountered:
piglikeYoung
changed the title
SlidingWindowMaximum Code error
“SlidingWindowMaximum” error
Nov 4, 2019
https://github.com/soapyigu/LeetCode-Swift/blob/master/Array/SlidingWindowMaximum.swift
testcase: [ 2, 3, 4, 2, 6, 2, 5, 1 ]
expected: [4, 4, 6, 6, 6, 5]
errorResult: [4, 4, 6, 6, 5, 5]
Modify
The text was updated successfully, but these errors were encountered: