No BB- The solution is in the picture
- Medium byte in half a year 11 times;
- Answer key:
- coding
public String convert3(String s, int numRows) {
char[] c = s.toCharArray();
int len = c.length;
StringBuilder[] sb = new StringBuilder[numRows];
int sbLen = sb.length;
int idx = 0;
// initialize sb[]
for (int i = 0; i < sbLen; i++) {
sb[i] = new StringBuilder();
}
while (idx < len) {
// 1: handle straight up and down;
for (int i = 0; i < numRows && idx < len; i++) {
sb[i].append(c[idx++]);
}
// 2: handle oblique (do I --)
for (int i = numRows - 2; i >= 1 && idx < len; i--) {
charcurrChar2 = c[idx++]; sb[i].append(currChar2); }}// sb[0] the hope of a village...
for (int i = 1; i < sbLen; i++) {
sb[0].append(sb[i]);
}
// 3: use the hope of the village, sb[0], string all the strings together;
return sb[0].toString();
}
Copy the code
The last
- Learn the algorithm, a word is not on the drawing, paoding cleniu, analysis of every step!