Description
Submission
class Solution { public: string convert(string s, int numRows) { int n = s.length(); vector<string> grid(numRows); int x = 0, dir = 1; for(int i = 0; i < n; ++i) { grid[x].push_back(s[i]); if(numRows > 1) x += dir; if(x == numRows - 1 || x == 0) { dir = -dir; } } string ret; for(auto& s: grid) { ret += s; } return ret; } }; // down: 1,0 // upper right: -1, 1 // down: 1, 0