最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

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

Leetcode 2027. Minimum Moves to Convert String

2023-01-19 15:17 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a string?s?consisting of?n?characters which are either?'X'?or?'O'.

A?move?is defined as selecting?three?consecutive characters?of?s?and converting them to?'O'. Note that if a move is applied to the character?'O', it will stay the?same.

Return?the?minimum?number of moves required so that all the characters of?s?are converted to?'O'.

?

Example 1:

Input: s = "XXX"Output: 1Explanation: XXX -> OOO We select all the 3 characters and convert them in one move.

Example 2:

Input: s = "XXOX"Output: 2Explanation: XXOX -> OOOX -> OOOO We select the first 3 characters in the first move, and convert them to 'O'. Then we select the last 3 characters and convert them so that the final string contains all 'O's.

Example 3:

Input: s = "OOOO"Output: 0Explanation: There are no 'X's in s to convert.

?

Constraints:

  • 3 <= s.length <= 1000

  • s[i]?is either?'X'?or?'O'.

因?yàn)橹荒芫徒?連續(xù)3個(gè),所以只要找到一個(gè)X,它后面2個(gè)不管是不是,就直接算進(jìn)去就行的。也就是i=i+3;step++;

然后如果沒有,就i++;依次往后面遍歷即可;

思路對(duì)了,做起來(lái)就很方便了。

Runtime0 ms

Beats

100%

Memory39.9 MB

Beats

98.73%


Leetcode 2027. Minimum Moves to Convert String的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
金川县| 泽普县| 龙岩市| 景宁| 松桃| 吴堡县| 淳化县| 两当县| 都安| 华池县| 万年县| 潍坊市| 南郑县| 青冈县| 陆丰市| 涟源市| 海阳市| 新乡县| 水富县| 永州市| 赣州市| 托克逊县| 扎鲁特旗| 渭源县| 平谷区| 台中县| 石台县| 浮梁县| 莆田市| 静海县| 宜宾县| 桐城市| 绥德县| 竹北市| 三门峡市| 栾城县| 湖北省| 道真| 涿州市| 黄梅县| 海晏县|