Skip to content

Commit 23292fb

Browse files
authored
Create 2379. Minimum Recolors to Get K Consecutive Black Blocks (#734)
2 parents 9cdedd3 + 06410ac commit 23292fb

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int minimumRecolors(string s, int k) {
4+
const int n = s.size();
5+
// if (k > n) return -1;
6+
int w = 0;
7+
for (int i = 0; i < k; ++i)
8+
w += s[i] == 'W';
9+
int minw = w;
10+
for (int i = k; i < n; ++i) {
11+
w += s[i] == 'W';
12+
w -= s[i - k] == 'W';
13+
minw = min(minw, w);
14+
// if (minw == 0) return 0;
15+
}
16+
return minw;
17+
}
18+
};

0 commit comments

Comments
 (0)