Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- string convert(string s, int numRows) {
- int size = s.size(), diagon = numRows - 2, t, tr;
- if (!size || numRows < 2 || numRows >= size)
- return s;
- string ans;
- for (int i = 0; i < numRows; ++i)
- {
- t = i;
- while (t < size)
- {
- ans.push_back(s[t]);
- tr = (numRows - 1 - i) * 2;
- if (i != 0 && i != numRows - 1 && t + tr < size)
- {
- ans.push_back(s[t + tr]);
- }
- t += numRows + diagon;
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment