6. Zigzag Conversion
6. Zigzag Conversion - Medium
Description¶
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)
1 2 3 |
|
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 |
|
这道题还是比较经典了,找到规律马上就解决了。
Solution¶
首先当numRows = 1
时,那么就不用处理,直接返回s
就行了;
如果numRows > 1
时,那我们就需要把字符串分成numRows
行了