class Solution {
public:
string convert(string s, int numRows) {
string str[numRows],tmp;
if(numRows == 1){
return s;
}
int flag;
for(int i = 0,j = 0;i < s.length(); i++){
if(j == 0){
flag = 1;
}
if(j == numRows-1){
flag = -1;
}
str[j] += s[i];
j += flag;
}
for(int i = 0;i < numRows; i++){
tmp += str[i];
}
return tmp;
}
};
i指向输入字符串s的每个字符,j分别指向str[0],str[1] ... str[numRows-1]即每一层的字符串,最后将每层字符串连接起来输出。