1 class Solution {
2 public:
3 string convert(string s, int numRows) {
4 vector<vector<char>> map;
5 map.resize(numRows);
6
7 for (int i = 0; i < numRows; i++)
8 map[i].resize(s.length());
9
10 int count = 0;
11 int j = 0;
12 while (count < s.length())
13 {
14 int i = 0;
15 while (count<s.length() && i<numRows)
16 map[i++][j]= s[count++];
17
18 j++; i--;
19 while (count<s.length() && i>1)
20 map[--i][j++] = s[count++];
21 }
22 string ans = "";
23 for (size_t i = 0; i < numRows;i++){
24 for (size_t j = 0; j < s.length(); j++){
25 if (map[i][j] != 0)
26 ans += map[i][j];
27 }
28 }
29 return ans;
30 }
31 };
32