<?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>row Archives - Huahua&#039;s Tech Road</title>
	<atom:link href="https://zxi.mytechroad.com/blog/tag/row/feed/" rel="self" type="application/rss+xml" />
	<link>https://zxi.mytechroad.com/blog/tag/row/</link>
	<description></description>
	<lastBuildDate>Thu, 13 Sep 2018 01:57:49 +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>row Archives - Huahua&#039;s Tech Road</title>
	<link>https://zxi.mytechroad.com/blog/tag/row/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>花花酱 LeetCode 6. ZigZag Conversion</title>
		<link>https://zxi.mytechroad.com/blog/simulation/leetcode-6-zigzag-conversion/</link>
					<comments>https://zxi.mytechroad.com/blog/simulation/leetcode-6-zigzag-conversion/#respond</comments>
		
		<dc:creator><![CDATA[zxi]]></dc:creator>
		<pubDate>Wed, 12 Sep 2018 15:54:49 +0000</pubDate>
				<category><![CDATA[Simulation]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[conversion]]></category>
		<category><![CDATA[medium]]></category>
		<category><![CDATA[row]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[zigzag]]></category>
		<guid isPermaLink="false">https://zxi.mytechroad.com/blog/?p=3923</guid>

					<description><![CDATA[<p>Problem The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a&#8230;</p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-6-zigzag-conversion/">花花酱 LeetCode 6. ZigZag Conversion</a> appeared first on <a rel="nofollow" href="https://zxi.mytechroad.com/blog">Huahua&#039;s Tech Road</a>.</p>
]]></description>
										<content:encoded><![CDATA[<h1><strong>Problem</strong></h1>
<p>The string <code>"PAYPALISHIRING"</code> is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)</p>
<pre class="crayon:false">P   A   H   N
A P L S I I G
Y   I   R
</pre>
<p>And then read line by line: <code>"PAHNAPLSIIGYIR"</code></p>
<p>Write the code that will take a string and make this conversion given a number of rows:</p>
<pre class="crayon:false">string convert(string s, int numRows);</pre>
<p><strong>Example 1:</strong><br />
&lt;preclass=&#8221;crayon:false&#8221;&gt;<strong>Input:</strong> s = &#8220;PAYPALISHIRING&#8221;, numRows = 3 <strong>Output:</strong> &#8220;PAHNAPLSIIGYIR&#8221;</p>
<p><strong>Example 2:</strong></p>
<pre class="crayon:false"><strong>Input:</strong> s = "PAYPALISHIRING", numRows = 4
<strong>Output:</strong> "PINALSIGYAHRPI"
<strong>Explanation:</strong>

P     I    N
A   L S  I G
Y A   H R
P     I</pre>
<h1><strong>Solution: Simulation</strong></h1>
<p>Store the zigzag results for each row and then output row by row.</p>
<p>Time complexity: O(n)</p>
<p>Space complexity: O(n)</p>
<p><div class="responsive-tabs">
<h2 class="tabtitle">C++</h2>
<div class="tabcontent">
</p><pre class="crayon-plain-tag">// Author: Huahua
class Solution {
public:
  string convert(string s, int nRows) {
    if (nRows == 1) return s;

    vector&lt;string&gt; ss(nRows);
    int l = s.length();
    int x = 0, y = 0, i = 0;
    bool down = true;
    while (i &lt; l) {
      ss[y] += s[i];
      if (down) {
        ++y;
        if (y == nRows) {
            down = false;
            y -=2;
        }
      } else {
        --y;
        if (y &lt; 0) {
            down = true;
            y = 1;
        }
      }
      i++;
    }

    string ans;
    for(const string&amp; r : ss)
      ans += r;
    return ans;
  }
};</pre><p></div></div></p>
<p>The post <a rel="nofollow" href="https://zxi.mytechroad.com/blog/simulation/leetcode-6-zigzag-conversion/">花花酱 LeetCode 6. ZigZag Conversion</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/simulation/leetcode-6-zigzag-conversion/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
