# 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; } } ```