mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<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> </p>
 | 
						|
<p><strong class="example">Example 1:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "XXX"
 | 
						|
<strong>Output:</strong> 1
 | 
						|
<strong>Explanation:</strong> <u>XXX</u> -> OOO
 | 
						|
We select all the 3 characters and convert them in one move.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 2:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "XXOX"
 | 
						|
<strong>Output:</strong> 2
 | 
						|
<strong>Explanation:</strong> <u>XXO</u>X -> O<u>OOX</u> -> OOOO
 | 
						|
We select the first 3 characters in the first move, and convert them to <code>'O'</code>.
 | 
						|
Then we select the last 3 characters and convert them so that the final string contains all <code>'O'</code>s.</pre>
 | 
						|
 | 
						|
<p><strong class="example">Example 3:</strong></p>
 | 
						|
 | 
						|
<pre>
 | 
						|
<strong>Input:</strong> s = "OOOO"
 | 
						|
<strong>Output:</strong> 0
 | 
						|
<strong>Explanation:</strong> There are no <code>'X's</code> in <code>s</code> to convert.
 | 
						|
</pre>
 | 
						|
 | 
						|
<p> </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>
 |