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

歡迎光臨散文網(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ó)家法律
射洪县| 象山县| 闻喜县| 丹阳市| 望江县| 巴林左旗| 涞水县| 贡嘎县| 巫溪县| 内乡县| 榆林市| 长乐市| 晋中市| 罗平县| 新郑市| 宁夏| 宜君县| 安化县| 广灵县| 普格县| 济阳县| SHOW| 耒阳市| 维西| 即墨市| 临洮县| 瑞安市| 绥芬河市| 文山县| 齐齐哈尔市| 广平县| 保康县| 波密县| 右玉县| 钟山县| 区。| 安国市| 渭源县| 宣化县| 江都市| 大余县|