mirror of
https://github.com/devenperez/leetcode.git
synced 2026-06-13 23:07:08 +00:00
47 lines
1.4 KiB
Markdown
47 lines
1.4 KiB
Markdown
<h2><a href="https://leetcode.com/problems/zigzag-conversion/">6. Zigzag Conversion</a></h2><h3>Medium</h3><hr><div><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>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>string convert(string s, int numRows);
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre><strong>Input:</strong> s = "PAYPALISHIRING", numRows = 3
|
|
<strong>Output:</strong> "PAHNAPLSIIGYIR"
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre><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>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre><strong>Input:</strong> s = "A", numRows = 1
|
|
<strong>Output:</strong> "A"
|
|
</pre>
|
|
|
|
<p> </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>
|
|
</div> |