tanchukw

Untitled

Jul 31st, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     string convert(string s, int numRows) {
  4.         int size = s.size(), diagon = numRows - 2, t, tr;
  5.         if (!size || numRows < 2 || numRows >= size)
  6.             return s;
  7.         string ans;
  8.         for (int i = 0; i < numRows; ++i)
  9.         {
  10.             t = i;
  11.             while (t < size)
  12.             {
  13.                 ans.push_back(s[t]);
  14.                 tr = (numRows - 1 - i) * 2;
  15.                 if (i != 0 && i != numRows - 1 && t + tr < size)
  16.                 {
  17.                     ans.push_back(s[t + tr]);
  18.                 }
  19.                 t += numRows + diagon;
  20.             }
  21.         }
  22.         return ans;
  23.     }
  24. };
Advertisement
Add Comment
Please, Sign In to add comment