<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>moves Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/moves/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/moves/</link>
	<description></description>
	<lastBuildDate>Tue, 05 Oct 2021 03:14:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.0.8</generator>

<image>
	<url>https://zxi.mytechroad.com/blog/wp-content/uploads/2017/09/cropped-photo-32x32.jpg</url>
	<title>moves Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/moves/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 2027. Minimum Moves to Convert String</title>
		<link>https://zxi.mytechroad.com/blog/string/leetcode-2027-minimum-moves-to-convert-string/</link>
					<comments>https://zxi.mytechroad.com/blog/string/leetcode-2027-minimum-moves-to-convert-string/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Tue, 05 Oct 2021 02:54:10 +0000</pubDate>
				<category><![CDATA[Array]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[easy]]></category>
		<category><![CDATA[moves]]></category>
		<category><![CDATA[string]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=8595</guid>

					<description><![CDATA[<p>You are given a string&#160;s&#160;consisting of&#160;n&#160;characters which are either&#160;'X'&#160;or&#160;'O'. A&#160;move&#160;is defined as selecting&#160;three&#160;consecutive characters&#160;of&#160;s&#160;and converting them to&#160;'O'. Note that if a move is applied to&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-2027-minimum-moves-to-convert-string/">花花酱 LeetCode 2027. Minimum Moves to Convert String</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>You are given a string&nbsp;<code>s</code>&nbsp;consisting of&nbsp;<code>n</code>&nbsp;characters which are either&nbsp;<code>'X'</code>&nbsp;or&nbsp;<code>'O'</code>.</p>



<p>A&nbsp;<strong>move</strong>&nbsp;is defined as selecting&nbsp;<strong>three</strong>&nbsp;<strong>consecutive characters</strong>&nbsp;of&nbsp;<code>s</code>&nbsp;and converting them to&nbsp;<code>'O'</code>. Note that if a move is applied to the character&nbsp;<code>'O'</code>, it will stay the&nbsp;<strong>same</strong>.</p>



<p>Return&nbsp;<em>the&nbsp;<strong>minimum</strong>&nbsp;number of moves required so that all the characters of&nbsp;</em><code>s</code><em>&nbsp;are converted to&nbsp;</em><code>'O'</code>.</p>



<p><strong>Example 1:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "XXX"
<strong>Output:</strong> 1
<strong>Explanation:</strong> XXX -&gt; OOO
We select all the 3 characters and convert them in one move.
</pre>



<p><strong>Example 2:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><strong>Input:</strong> s = "XXOX"
<strong>Output:</strong> 2
<strong>Explanation:</strong> XXOX -&gt; OOOX -&gt; 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>Example 3:</strong></p>



<pre class="wp-block-preformatted;crayon:false"><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><strong>Constraints:</strong></p>



<ul><li><code>3 &lt;= s.length &lt;= 1000</code></li><li><code>s[i]</code>&nbsp;is either&nbsp;<code>'X'</code>&nbsp;or&nbsp;<code>'O'</code>.</li></ul>



<h2><strong>Solution: Straight Forward</strong></h2>



<p>if s[i] == &#8216;X&#8217;, change s[i], s[i + 1] and s[i + 2] to &#8216;O&#8217;.</p>



<p>Time complexity: O(n)<br>Space complexity: O(1)</p>



<div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">

<pre class="crayon-plain-tag">class Solution {
public:
  int minimumMoves(string s) {
    const int n = s.length();
    int ans = 0;
    for (size_t i = 0; i &lt; n; ++i) {
      if (s[i] == 'X') {
        ans += 1;
        i += 2;
      }
    }
    return ans;
  }
};</pre>
</div></div>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/string/leetcode-2027-minimum-moves-to-convert-string/">花花酱 LeetCode 2027. Minimum Moves to Convert String</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://zxi.mytechroad.com/blog/string/leetcode-2027-minimum-moves-to-convert-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
