← 返回 amazon 的题目列表Zigzag String Conversion on N Rows
类型:online_judge
amazon
Given a string, you need to arrange it in a Z pattern on a given number of rows. After arranging, read the characters in each row from top to bottom and left to right to generate a new string.
For example, the input string is "PAYPALISHIRING" and the number of rows is 3, the arrangement is as follows:
P A H N
A P L S I I G
Y I R
Return the result "PAHNAPLSIIGYIR". Please implement a conversion function.
Input:
s: A string representing the string to be converted.
numRows: An integer representing the number of rows in Z pattern.
Output: Return a string representing the converted string.
Example:
s = "PAYPALISHIRING"
numRows = 3
# Returns: "PAHNAPLSIIGYIR"
Constraints:
1 <= s.length <= 1000
1 <= numRows <= 1000
Example
Input
PAYPALISHIRING
3