class Solution {
public String convert(String s, int numRows) {
if(numRows == 1) return s;
int n = s.length();
StringBuilder[] sb = new StringBuilder[numRows];
int row = 0;
int dir = 1;
for(int i = 0; i < n; i++) {
if(sb[row] == null) sb[row] = new StringBuilder();
sb[row].append(s.charAt(i));
if(row == numRows - 1 || ((row == 0) && (i != 0))) dir = -dir;
row += dir;
}
StringBuilder result = new StringBuilder();
for(int i = 0; i < numRows; i++) {
if(sb[i] == null) continue;
result.append(sb[i]);
}
return result.toString();
}
}