【leetcode-python-8】面试题59 - I. 滑动窗口的最大值
参考大佬版1(77.12%)
这种类型的题得用单调栈。这个版本没有用deque。
注:参考题解区Krahets思路。
class Solution(object):
def maxSlidingWindow(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
s = []
p = []
if not nums or k == 0:
return []
for ki in range(k):
while s and s[-1] < nums[ki]:
s.pop()
s.app