java.lang.Object
g2001_2100.s2027_minimum_moves_to_convert_string.Solution

public class Solution extends Object
2027 - Minimum Moves to Convert String.<p>Easy</p> <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> <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> <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> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;XXX&rdquo;</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> XXX -> OOO We select all the 3 characters and convert them in one move.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;XXOX&rdquo;</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> XXOX -> OOOX -> OOOO</p> <p>We select the first 3 characters in the first move, and convert them to <code>'O'</code>.</p> <p>Then we select the last 3 characters and convert them so that the final string contains all <code>'O'</code>s.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;OOOO&rdquo;</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> There are no <code>'X's</code> in <code>s</code> to convert.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>3 <= s.length <= 1000</code></li> <li><code>s[i]</code> is either <code>'X'</code> or <code>'O'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimumMoves

      public int minimumMoves(String s)