水题。
class Solution {
public:
string convert(string s, int numRows) {
if (1 == numRows) {
return s;
}
vector<string> v_s(numRows);
int length = s.length();
int next_line = 0;
bool direction = true;
for (int idx = 0; idx < length; idx++) {
v_s[next_line] = v_s[next_line] + s[idx];
if (direction) {
next_line++;
} else {
next_line--;
}
if (next_line >= numRows) {
direction = !direction;
next_line -= 2;
}
if (next_line < 0) {
direction = !direction;
next_line += 2;
}
}
string result;
for (int idx = 0; idx < numRows; idx++) {
result += v_s[idx];
}
return result;
}
};