|
| 1 | +<h2><a href="https://leetcode.com/problems/minimum-moves-to-convert-string">2027. Minimum Moves to Convert String</a></h2><h3>Easy</h3><hr><p>You are given a string <code>s</code> consisting of <code>n</code> characters which are either <code>'X'</code> or <code>'O'</code>.</p> |
| 2 | + |
| 3 | +<p>A <strong>move</strong> is defined as selecting <strong>three</strong> <strong>consecutive characters</strong> of <code>s</code> and converting them to <code>'O'</code>. Note that if a move is applied to the character <code>'O'</code>, it will stay the <strong>same</strong>.</p> |
| 4 | + |
| 5 | +<p>Return <em>the <strong>minimum</strong> number of moves required so that all the characters of </em><code>s</code><em> are converted to </em><code>'O'</code>.</p> |
| 6 | + |
| 7 | +<p> </p> |
| 8 | +<p><strong class="example">Example 1:</strong></p> |
| 9 | + |
| 10 | +<pre> |
| 11 | +<strong>Input:</strong> s = "XXX" |
| 12 | +<strong>Output:</strong> 1 |
| 13 | +<strong>Explanation:</strong> <u>XXX</u> -> OOO |
| 14 | +We select all the 3 characters and convert them in one move. |
| 15 | +</pre> |
| 16 | + |
| 17 | +<p><strong class="example">Example 2:</strong></p> |
| 18 | + |
| 19 | +<pre> |
| 20 | +<strong>Input:</strong> s = "XXOX" |
| 21 | +<strong>Output:</strong> 2 |
| 22 | +<strong>Explanation:</strong> <u>XXO</u>X -> O<u>OOX</u> -> OOOO |
| 23 | +We select the first 3 characters in the first move, and convert them to <code>'O'</code>. |
| 24 | +Then we select the last 3 characters and convert them so that the final string contains all <code>'O'</code>s.</pre> |
| 25 | + |
| 26 | +<p><strong class="example">Example 3:</strong></p> |
| 27 | + |
| 28 | +<pre> |
| 29 | +<strong>Input:</strong> s = "OOOO" |
| 30 | +<strong>Output:</strong> 0 |
| 31 | +<strong>Explanation:</strong> There are no <code>'X's</code> in <code>s</code> to convert. |
| 32 | +</pre> |
| 33 | + |
| 34 | +<p> </p> |
| 35 | +<p><strong>Constraints:</strong></p> |
| 36 | + |
| 37 | +<ul> |
| 38 | + <li><code>3 <= s.length <= 1000</code></li> |
| 39 | + <li><code>s[i]</code> is either <code>'X'</code> or <code>'O'</code>.</li> |
| 40 | +</ul> |
0 commit comments