forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_2379.java
33 lines (32 loc) · 966 Bytes
/
_2379.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.fishercoder.solutions;
public class _2379 {
public static class Solution1 {
public int minimumRecolors(String blocks, int k) {
int min = k;
int left = 0;
int right = 0;
int recolors = 0;
while (right - left < k) {
if (blocks.charAt(right) == 'W') {
recolors++;
}
right++;
}
if (right - left == k) {
min = Math.min(recolors, min);
}
while (right < blocks.length() && left < blocks.length() - k) {
if (blocks.charAt(right) == 'W') {
recolors++;
}
right++;
if (blocks.charAt(left) == 'W') {
recolors--;
}
left++;
min = Math.min(recolors, min);
}
return min;
}
}
}