LeetCode 6.ZigZag Conversion
问题描述:
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 fixed font for better legibility)
And then read line by line: “PAHNAPLSIIGYIR”
Write the code that will take a string and make this conversion given a number of rows:1
string convert(string s, int numRows);
样例如下
Example 1:1
2Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"
Example 2:1
2Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:
解题思路:
弄一个numRows * s.length()的数组,便利s,按规律插入就行了
代码如下:
1 | class Solution { |