Skip to content

Latest commit

 

History

History

006.ZigZag Conversion

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
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: 
string convert(string text, int nRows);
convert("PAYPALISHIRING", 3) should return "PAHNAPLSIIGYIR". 

按照ZIGZAG扫描字符串。
每行用一个string记录,index记录第几行,扫描时碰到
边界则反向。也可以直接算每行对应第几个字母来实现。