题目链接;力扣 分析:找规律 我的答案:
String convert(String s, int numRows) {
if (numRows == 1){
return s;
}
StringBuilder newString = new StringBuilder();
int length = s.length();
int temp = 2 * numRows - 2;//循环周期
for (int i = 0; i < numRows; i++) {
for (int j = 0; i + j < length; j += temp){
newString.append(s.charAt(i + j));
if (i != 0 && i != temp - 1 && j + temp - i != i + j && j + temp - i < length) {
newString.append(s.charAt(j + temp - i));
}
}
}
return newString.toString();
}