Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
- from collections import deque
- q = deque()
- ans = []
- for r in range(len(nums)):
- while q and q[0]<=r-k:
- q.popleft()
- while q and nums[q[-1]]<nums[r]:
- q.pop()
- q.append(r)
- if r>=k-1:
- ans.append(q[0])
- return [nums[i] for i in ans]
Advertisement
Add Comment
Please, Sign In to add comment