力扣:面试题59. 滑动窗口的最大值Python题解
C++做出这道题好像没什么值得炫耀的,来练习Python吧
class Solution(object):
def maxSlidingWindow(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
ans = []
if len(nums) == 0:
return []
for i in range(0, len(nums) - (k - 1)):
MAX = -10000001
for j in range(i, i + k):
if MAX < nums[j]:
MAX = nums[j]
ans.append(MAX)
return ans