6. ZigZag Conversion
Problem
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:
convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR".
Related Topics:
String
Analysis
可以发现:
每一完整的列,其差值为
2 * numRows - 2
。斜线左右分割这差值,其上下层之间,分割的差值
±2
。
Code
Last updated