1
# Runtime: 4951 ms (Top 7.51%) | Memory: 39.4 MB (Top 5.02%)
2
class Solution:
3
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
4
ans = []
5
pq = []
6

7
for i in range(k):
8
heapq.heappush(pq, (-nums[i], i))
9

10
ans.append(-pq[0][0])
11

12
for i in range(k, len(nums)):
13
heapq.heappush(pq, (-nums[i], i))
14
while pq and pq[0][1] < i - k + 1:
15
heapq.heappop(pq)
16
ans.append(-pq[0][0])
17

18
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0