Python Solution (linear on (len(nums)+k) )


  • 0
    R
    class Solution(object):
        def maxSlidingWindow(self, nums, k):
            if(len(nums) == 0):
                return []
            if(k > len(nums)):
                return []
            if(k == 1):
                return nums
    
            l = []        
            max1 = max(nums[0:k])
            l.append(max1)
            i = k
            while(i < len(nums)):
                max1 = max(nums[i-k+1:i+1])
                l.append(max1)
                i += 1
            return l
    
    

Log in to reply
 

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