五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

Leetcode 2379. Minimum Recolors to Get K Consecutive Black Block

2023-02-11 16:47 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?string?blocks?of length?n, where?blocks[i]?is either?'W'?or?'B', representing the color of the?ith?block. The characters?'W'?and?'B'?denote the colors white and black, respectively.

You are also given an integer?k, which is the desired number of?consecutive?black blocks.

In one operation, you can?recolor?a white block such that it becomes a black block.

Return?the?minimum?number of operations needed such that there is at least?one?occurrence of?k?consecutive black blocks.

?

Example 1:

Input: blocks = "WBBWWBBWBW", k = 7Output: 3Explanation:One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks so that blocks = "BBBBBBBWBW". It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations. Therefore, we return 3.

Example 2:

Input: blocks = "WBWBBBW", k = 2Output: 0Explanation:No changes need to be made, since 2 consecutive black blocks already exist. Therefore, we return 0.

?

Constraints:

  • n == blocks.length

  • 1 <= n <= 100

  • blocks[i]?is either?'W'?or?'B'.

  • 1 <= k <= n



使用前綴和的時(shí)候,要多一個(gè)位置,這也是就一直沒(méi)解決的原因,尷尬;

同時(shí)也可以使用sliding window來(lái)解決;

Runtime:?1 ms, faster than?85.02%?of?Java?online submissions for?Minimum Recolors to Get K Consecutive Black Blocks.

Memory Usage:?40.4 MB, less than?52.26%?of?Java?online submissions for?Minimum Recolors to Get K Consecutive Black Blocks.


Leetcode 2379. Minimum Recolors to Get K Consecutive Black Block的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
浦城县| 银川市| 绥芬河市| 邵武市| 鄂尔多斯市| 陈巴尔虎旗| 百色市| 浦县| 北海市| 洛阳市| 剑阁县| 龙胜| 德钦县| 临夏市| 喜德县| 徐闻县| 黄山市| 水富县| 张家界市| 莒南县| 宜宾县| 德昌县| 花莲县| 雷山县| 镇宁| 晴隆县| 普兰店市| 叙永县| 泸州市| 湟源县| 余干县| 静乐县| 图们市| 济宁市| 镇宁| 丘北县| 武穴市| 内江市| 廉江市| 长兴县| 遂宁市|