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)
P A H N
A P L S I I G
Y I R
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”.
2. Analysis
ZigZag 即循环对角结构:
nRows = 2
0 2 4 6 8
1 3 5 7 9
nRows = 3
0 4 8
1 3 5 7 9
2 6
nRows = 4
0 6
1 5 7
2 4 8
3 9
3. Solution(s)
|
|
近期评论