# 2379. Minimum Recolors to Get K Consecutive Black Blocks ###### tags: `Leetcode` `Easy` `Sliding Window` Link: https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/description/ ## 思路 fixed length sliding window ## Code ```java= class Solution { public int minimumRecolors(String blocks, int k) { int cnt = 0, ans = Integer.MAX_VALUE; for(int i=0; i<blocks.length(); i++){ if(blocks.charAt(i)=='W') cnt++; if(i>=k-1){ if(i>=k && blocks.charAt(i-k)=='W') cnt--; ans = Math.min(ans, cnt); } } 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