2027. Minimum Moves to Convert String Easy

@problem@discussion
#String#Greedy



1/**
2 * [2027] Minimum Moves to Convert String
3 *
4 * You are given a string s consisting of n characters which are either 'X' or 'O'.
5 * 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.
6 * Return the minimum number of moves required so that all the characters of s are converted to 'O'.
7 *  
8 * Example 1:
9 * 
10 * Input: s = "XXX"
11 * Output: 1
12 * Explanation: <u>XXX</u> -> OOO
13 * We select all the 3 characters and convert them in one move.
14 * 
15 * Example 2:
16 * 
17 * Input: s = "XXOX"
18 * Output: 2
19 * Explanation: <u>XXO</u>X -> O<u>OOX</u> -> OOOO
20 * We select the first 3 characters in the first move, and convert them to 'O'.
21 * Then we select the last 3 characters and convert them so that the final string contains all 'O's.
22 * Example 3:
23 * 
24 * Input: s = "OOOO"
25 * Output: 0
26 * Explanation: There are no 'X's in s to convert.
27 * 
28 *  
29 * Constraints:
30 * 
31 * 	3 <= s.length <= 1000
32 * 	s[i] is either 'X' or 'O'.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/minimum-moves-to-convert-string/
38// discuss: https://leetcode.com/problems/minimum-moves-to-convert-string/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn minimum_moves(s: String) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_2027() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.