LeetCode 6. ZigZag Conversion
水题
class Solution {
public:
string convert(string s, int numRows) {
if(numRows <= 1)
return s;
string str[numRows];
int row = 0, add;
for(int i=0; i<s.size(); ++ i)
{
str[row] += s[i];
if(row == 0)
add = 1;
if(row == numRows - 1)
add = -1;
row += add;
}
s.clear();
for(int i=0; i<numRows; ++ i)
s.append(str[i]);
return s;
}
};