Class Solution

java.lang.Object
g0001_0100.s0006_zigzag_conversion.Solution

public class Solution extends Object
6 - Zigzag Conversion.<p>Medium</p> <p>The string <code>&quot;PAYPALISHIRING&quot;</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>&quot;PAHNAPLSIIGYIR&quot;</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 = &ldquo;PAYPALISHIRING&rdquo;, numRows = 3</p> <p><strong>Output:</strong> &ldquo;PAHNAPLSIIGYIR&rdquo;</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;PAYPALISHIRING&rdquo;, numRows = 4</p> <p><strong>Output:</strong> &ldquo;PINALSIGYAHRPI&rdquo;</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 = &ldquo;A&rdquo;, numRows = 1</p> <p><strong>Output:</strong> &ldquo;A&rdquo;</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>
  • Constructor Details Link icon

    • Solution Link icon

      public Solution()
  • Method Details Link icon