题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/08bab45600c9d450029e37727be59d06.png)
代码
class Solution {
public String convert(String s, int numRows) {
if(s == null || s.length()<1 || numRows ==1) return s;
StringBuilder[] array = new StringBuilder[numRows];
int dir = 1,index = 0;
for(int i = 0; i< numRows; i++) array[i] = new StringBuilder();
for(char c: s.toCharArray()){
array[index].append(c);
index= index+dir;
if(index == numRows-1 || index == 0){
dir = -dir;
}
}
StringBuilder result = new StringBuilder();
for(int i =0; i< numRows;i++) result.append(array[i]);
return result.toString();
}
}
结果
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/1442c2eb2fb94877003c32ee0f1ff155.png)