Last active
October 20, 2015 06:02
-
-
Save lzdhlsc/3d0896b9137c3109af3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# collections.deque 如何? | |
# https://leetcode.com/problems/sliding-window-maximum/ | |
dq = collections.deque() # dq keeps track of min(d[i] + a[i]) from i-1 to i-k | |
d[i] = dq[-1] | |
while len(dp) and dq[-1][0] >= d[i] + a[i]: | |
dq.pop() | |
dq.append((d[i] + a[i], i)) | |
if dq[0][1] == i - k: | |
dp.popleft() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment