Python concise solution


  • 0
    Y
    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
                else:
                    mv = -sys.maxint
                    for j in range(i-k+1, i+1):
                        if mv <= nums[j]:
                            mv = nums[j]
                            mp = j
                r.append(mv)
            return r

Log in to reply
 

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