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)
字符串”PAYPALISHIRING”写的是在一个给定的行数,这样一个曲折的模式:(你可能想在一个固定的字体更加易读显示模式)
也就是说,给定一个字符串和行数,将字符串按照从左至右,从上至下的形式(Z 字形)排列,然后按行输出。如图。
And then read line by line: (输出)”PAHNAPLSIIGYIR”
string convert(string text, int nRows);
convert(“PAYPALISHIRING”, 3) should return “PAHNAPLSIIGYIR”.
(1)str[索引值] (2)str.charAt(索引值) (3)字符串->数组:str.split(“”)
var cyc = 2*numRows - 2;
因为,不管行数是多少,两列之间所有的字符都可以缩成一行,但是总会差首行和末行两个字符,加上第一列的字符,得出计算公式。var mid = j + cyc - 2*i;