Class Solution
java.lang.Object
g0001_0100.s0006_zigzag_conversion.Solution
6 - Zigzag Conversion.<p>Medium</p>
<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>
<p>P A H N A P L S I I G Y I R</p>
<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>
<p>string convert(string s, int numRows);</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “PAYPALISHIRING”, numRows = 3</p>
<p><strong>Output:</strong> “PAHNAPLSIIGYIR”</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “PAYPALISHIRING”, numRows = 4</p>
<p><strong>Output:</strong> “PINALSIGYAHRPI”</p>
<p><strong>Explanation:</strong> P I N A L S I G Y A H R P I</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “A”, numRows = 1</p>
<p><strong>Output:</strong> “A”</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 1000</code></li>
<li><code>s</code> consists of English letters (lower-case and upper-case), <code>','</code> and <code>'.'</code>.</li>
<li><code>1 <= numRows <= 1000</code></li>
</ul>