[LeetCode][Python3] 239. Sliding Window Maximum
2019. 3. 29. 00:41 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/sliding-window-maximum/
My Solution :
from collections import deque
class Solution:
def maxSlidingWindow(self, nums: List[int], k: int) -> List[int]:
dq = deque()
ret = []
for i in range(len(nums)):
if dq and dq[0] == i-k:
dq.popleft()
while dq and nums[dq[-1]] <= nums[i]:
dq.pop()
dq.append(i)
if k-1 <= i:
ret.append(nums[dq[0]])
return ret
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 236. Lowest Common Ancestor of a Binary Tree (0) | 2019.04.01 |
---|---|
[LeetCode][Python3] 207. Course Schedule (0) | 2019.03.31 |
[LeetCode][Python3] 116. Populating Next Right Pointers in Each Node (0) | 2019.03.30 |
[LeetCode][Python3] 208. Implement Trie (Prefix Tree) (1) | 2019.03.30 |
[LeetCode][Python3] 315. Count of Smaller Numbers After Self (0) | 2019.03.28 |
[LeetCode][Python3] 395. Longest Substring with At Least K Repeating Characters (0) | 2019.03.28 |
[LeetCode][Python3] 73. Set Matrix Zeroes (0) | 2019.03.27 |
[LeetCode][Python3] 329. Longest Increasing Path in a Matrix (0) | 2019.03.27 |
최근에 달린 댓글 최근에 달린 댓글