Skip to content

Commit 21db5d2

Browse files
committed
✨ upload 2379th cpp solution
1 parent 1c08387 commit 21db5d2

File tree

1 file changed

+20
-0
lines changed
  • LeetCode/2379. Minimum Recolors to Get K Consecutive Black Blocks

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Runtime: 4 ms
3+
* Memory Usage: 6.1 MB
4+
*/
5+
class Solution {
6+
public:
7+
int minimumRecolors(string blocks, int k) {
8+
int i = 0, tmp = 0;
9+
while (i < k) {
10+
tmp += blocks[i++] == 'W';
11+
}
12+
int ans = tmp;
13+
for (; i < blocks.size() ; ++ i) {
14+
tmp += blocks[i] == 'W';
15+
tmp -= blocks[i - k] == 'W';
16+
ans = min(ans, tmp);
17+
}
18+
return ans;
19+
}
20+
};

0 commit comments

Comments
 (0)