无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(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ó)家法律
和平县| 壤塘县| 鹤岗市| 新巴尔虎左旗| 福鼎市| 鹰潭市| 汝阳县| 佛冈县| 隆昌县| 溆浦县| 台山市| 两当县| 白银市| 台东县| 天镇县| 遵化市| 观塘区| 隆昌县| 清徐县| 安塞县| 阳西县| 永宁县| 英德市| 宜川县| 湘潭市| 汤原县| 洛南县| 灵璧县| 柞水县| 彩票| 天等县| 衢州市| 容城县| 桂平市| 凤台县| 独山县| 乌拉特后旗| 大厂| 宜兰县| 三门县| 白玉县|