class Solution {
public:
string convert(string s, int nRows) {
string ret = "";
string* lines = new string[nRows];
int linenum = 0;
int dir = 1;
while (s != "") {
lines[linenum].append(1, s[0]);
s = s.substr(1,s.length()-1);
if (linenum == nRows-1) dir = -1;
if (linenum == 0) dir = 1;
linenum = (linenum+dir)%nRows;
}
for (int i=0; i<nRows; ++i) {
ret.append(lines[i]);
}
return ret;
}
};
转载于:https://my.oschina.net/yamamaki/blog/226818