Python concise solution

  • 0
    import sys
    class Solution(object):
        def maxSlidingWindow(self, nums, k):
            if not nums: return []
            mp = -1
            r = []
            for i in range(k-1, len(nums)):
                if mp > i-k:
                    if nums[i] >= mv:
                        mv = nums[i]
                        mp = i
                    mv = -sys.maxint
                    for j in range(i-k+1, i+1):
                        if mv <= nums[j]:
                            mv = nums[j]
                            mp = j
            return r

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.