MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / maxSlidingWindow

Method maxSlidingWindow

Array/SlidingWindowMaximum.py:62–88  ·  view source on GitHub ↗

:type nums: List[int] :type k: int :rtype: List[int]

(self, nums, k)

Source from the content-addressed store, hash-verified

60 hi = mid
61
62 def maxSlidingWindow(self, nums, k):
63 """
64 :type nums: List[int]
65 :type k: int
66 :rtype: List[int]
67 """
68 if not nums:
69 return []
70
71 x = nums[:k]
72 y = sorted(x)
73 x = deque(x)
74
75 maxes = max(x)
76 result = [maxes]
77
78 for i in nums[k:]:
79 pop = x.popleft()
80 x.append(i)
81
82 index = self.find_bi(y, pop)
83 y.pop(index)
84
85 bisect.insort_left(y, i)
86
87 result.append(y[-1])
88 return result
89

Callers

nothing calls this directly

Calls 2

find_biMethod · 0.95
popMethod · 0.45

Tested by

no test coverage detected