# 1052. Grumpy Bookstore Owner ###### tags: `Leetcode` `Medium` `Sliding Window` Link: https://leetcode.com/problems/grumpy-bookstore-owner/ ## 思路 fixed length sliding window ## Code ```java= class Solution { public int maxSatisfied(int[] customers, int[] grumpy, int minutes) { int base = 0; for(int i=0; i<grumpy.length; i++){ if(grumpy[i]==0){ base+=customers[i]; } } int ans = 0; int curr = base; for(int i=0; i<customers.length; i++){ if(grumpy[i]==1){ curr+=customers[i]; } if(i-minutes>=0 && grumpy[i-minutes]==1){ curr-=customers[i-minutes]; } ans = Math.max(ans, curr); } return ans; } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up